home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Source / GNU / cc / cp-typeck.c < prev    next >
C/C++ Source or Header  |  1994-02-07  |  215KB  |  6,835 lines

  1. /* Build expressions with type checking for C++ compiler.
  2.    Copyright (C) 1987, 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@cygnus.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* This file is part of the C++ front end.
  23.    It contains routines to build C++ expressions given their operands,
  24.    including computing the types of the result, C and C++ specific error
  25.    checks, and some optimization.
  26.  
  27.    There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
  28.    and to process initializations in declarations (since they work
  29.    like a strange sort of assignment).  */
  30.  
  31. extern void error ();
  32. extern void warning ();
  33.  
  34. #include "config.h"
  35. #include <stdio.h>
  36. #include "tree.h"
  37. #include "rtl.h"
  38. #include "cp-tree.h"
  39. #include "flags.h"
  40.  
  41. int mark_addressable ();
  42. static tree convert_for_assignment ();
  43. /* static */ tree convert_for_initialization ();
  44. int compparms ();
  45. static int self_promoting_args_p ();
  46. int comp_target_types ();
  47. extern tree shorten_compare ();
  48. void warn_for_assignment ();
  49. extern void binary_op_error ();
  50. static tree pointer_int_sum ();
  51. static tree pointer_diff ();
  52. static tree convert_sequence ();
  53. /* static */ tree unary_complex_lvalue ();
  54. static void pedantic_lvalue_warning ();
  55. tree truthvalue_conversion ();
  56.  
  57. extern rtx original_result_rtx;
  58.  
  59. /* Return the target type of TYPE, which meas return T for:
  60.    T*, T&, T[], T (...), and otherwise, just T.  */
  61.  
  62. tree
  63. target_type (type)
  64.      tree type;
  65. {
  66.   if (TREE_CODE (type) == REFERENCE_TYPE)
  67.     type = TREE_TYPE (type);
  68.   while (TREE_CODE (type) == POINTER_TYPE
  69.      || TREE_CODE (type) == ARRAY_TYPE
  70.      || TREE_CODE (type) == FUNCTION_TYPE
  71.      || TREE_CODE (type) == METHOD_TYPE
  72.      || TREE_CODE (type) == OFFSET_TYPE)
  73.     type = TREE_TYPE (type);
  74.   return type;
  75. }
  76.  
  77. /* Do `exp = require_complete_type (exp);' to make sure exp
  78.    does not have an incomplete type.  (That includes void types.)  */
  79.  
  80. tree
  81. require_complete_type (value)
  82.      tree value;
  83. {
  84.   tree type = TREE_TYPE (value);
  85.  
  86.   /* First, detect a valid value with a complete type.  */
  87.   if (TYPE_SIZE (type) != 0
  88.       && type != void_type_node)
  89.     return value;
  90.  
  91.   /* If we see X::Y, we build an OFFSET_TYPE which has
  92.      not been laid out.  Try to avoid an error by interpreting
  93.      it as this->X::Y, if reasonable.  */
  94.   if (TREE_CODE (value) == OFFSET_REF
  95.       && C_C_D != 0
  96.       && TREE_OPERAND (value, 0) == C_C_D)
  97.     {
  98.       tree base, member = TREE_OPERAND (value, 1);
  99.       tree basetype = TYPE_OFFSET_BASETYPE (type);
  100.       my_friendly_assert (TREE_CODE (member) == FIELD_DECL, 305);
  101.       base = convert_pointer_to (basetype, current_class_decl);
  102.       value = build (COMPONENT_REF, TREE_TYPE (member),
  103.              build_indirect_ref (base, NULL_PTR), member);
  104.       return require_complete_type (value);
  105.     }
  106.  
  107.   incomplete_type_error (value, type);
  108.   return error_mark_node;
  109. }
  110.  
  111. /* Return truthvalue of whether type of EXP is instantiated.  */
  112. int
  113. type_unknown_p (exp)
  114.      tree exp;
  115. {
  116.   return (TREE_CODE (exp) == TREE_LIST
  117.       || TREE_TYPE (exp) == unknown_type_node
  118.       || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
  119.           && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node));
  120. }
  121.  
  122. /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
  123.    does not have an uninstantiated type.
  124.    TYPE is type to instantiate with, if uninstantiated.  */
  125. tree
  126. require_instantiated_type (type, exp, errval)
  127.      tree type, exp, errval;
  128. {
  129.   if (TREE_TYPE (exp) == NULL_TREE)
  130.     {
  131.       error ("argument list may not have an initializer list");
  132.       return errval;
  133.     }
  134.  
  135.   if (TREE_TYPE (exp) == unknown_type_node
  136.       || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
  137.       && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node))
  138.     {
  139.       exp = instantiate_type (type, exp, 1);
  140.       if (TREE_TYPE (exp) == error_mark_node)
  141.     return errval;
  142.     }
  143.   return exp;
  144. }
  145.  
  146. /* Return a variant of TYPE which has all the type qualifiers of LIKE
  147.    as well as those of TYPE.  */
  148.  
  149. static tree
  150. qualify_type (type, like)
  151.      tree type, like;
  152. {
  153.   int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
  154.   int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
  155.   /* @@ Must do member pointers here.  */
  156.   return build_type_variant (type, constflag, volflag);
  157. }
  158.  
  159. /* Return the common type of two parameter lists.
  160.    We assume that comptypes has already been done and returned 1;
  161.    if that isn't so, this may crash.
  162.  
  163.    As an optimization, free the space we allocate if the parameter
  164.    lists are already common.  */
  165.  
  166. tree
  167. commonparms (p1, p2)
  168.      tree p1, p2;
  169. {
  170.   tree oldargs = p1, newargs, n;
  171.   int i, len;
  172.   int any_change = 0;
  173.   char *first_obj = (char *) oballoc (0);
  174.  
  175.   len = list_length (p1);
  176.   newargs = tree_last (p1);
  177.  
  178.   if (newargs == void_list_node)
  179.     i = 1;
  180.   else
  181.     {
  182.       i = 0;
  183.       newargs = 0;
  184.     }
  185.  
  186.   for (; i < len; i++)
  187.     newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
  188.  
  189.   n = newargs;
  190.  
  191.   for (i = 0; p1;
  192.        p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n), i++)
  193.     {
  194.       if (TREE_PURPOSE (p1) && !TREE_PURPOSE (p2))
  195.     {
  196.       /* We used to give a warning here that advised about a default
  197.          argument being given in the prototype but not in the function's
  198.          declaration.  It's best not to bother.  */
  199.       TREE_PURPOSE (n) = TREE_PURPOSE (p1);
  200.       any_change = 1;
  201.     }
  202.       else if (! TREE_PURPOSE (p1))
  203.     {
  204.       if (TREE_PURPOSE (p2))
  205.         {
  206.           TREE_PURPOSE (n) = TREE_PURPOSE (p2);
  207.           any_change = 1;
  208.         }
  209.     }
  210.       else
  211.     {
  212.       int cmp = simple_cst_equal (TREE_PURPOSE (p1), TREE_PURPOSE (p2));
  213.       if (cmp < 0)
  214.         my_friendly_abort (111);
  215.       if (cmp == 0)
  216.         {
  217.           error ("redeclaration of default argument %d", i+1);
  218.           any_change = 1;
  219.         }
  220.       TREE_PURPOSE (n) = TREE_PURPOSE (p2);
  221.     }
  222.       if (TREE_VALUE (p1) != TREE_VALUE (p2))
  223.     {
  224.       any_change = 1;
  225.       TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
  226.     }
  227.       else
  228.     TREE_VALUE (n) = TREE_VALUE (p1);
  229.     }
  230.   if (! any_change)
  231.     {
  232.       obfree (first_obj);
  233.       return oldargs;
  234.     }
  235.  
  236.   return newargs;
  237. }
  238.  
  239. /* Return the common type of two types.
  240.    We assume that comptypes has already been done and returned 1;
  241.    if that isn't so, this may crash.
  242.  
  243.    This is the type for the result of most arithmetic operations
  244.    if the operands have the given two types.
  245.  
  246.    We do not deal with enumeral types here because they have already been
  247.    converted to integer types.  */
  248.  
  249. tree
  250. common_type (t1, t2)
  251.      tree t1, t2;
  252. {
  253.   register enum tree_code code1;
  254.   register enum tree_code code2;
  255.  
  256.   /* Save time if the two types are the same.  */
  257.  
  258.   if (t1 == t2) return t1;
  259.  
  260.   /* If one type is nonsense, use the other.  */
  261.   if (t1 == error_mark_node)
  262.     return t2;
  263.   if (t2 == error_mark_node)
  264.     return t1;
  265.  
  266.   /* Treat an enum type as the unsigned integer type of the same width.  */
  267.  
  268.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  269.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  270.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  271.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  272.  
  273.   code1 = TREE_CODE (t1);
  274.   code2 = TREE_CODE (t2);
  275.  
  276.   switch (code1)
  277.     {
  278.     case INTEGER_TYPE:
  279.     case REAL_TYPE:
  280.       /* If only one is real, use it as the result.  */
  281.  
  282.       if (code1 == REAL_TYPE && code2 != REAL_TYPE)
  283.     return t1;
  284.  
  285.       if (code2 == REAL_TYPE && code1 != REAL_TYPE)
  286.     return t2;
  287.  
  288.       /* Both real or both integers; use the one with greater precision.  */
  289.  
  290.       if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
  291.     return t1;
  292.       else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
  293.     return t2;
  294.  
  295.       /* Same precision.  Prefer longs to ints even when same size.  */
  296.  
  297.       if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
  298.       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
  299.     return long_unsigned_type_node;
  300.  
  301.       if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
  302.       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
  303.     {
  304.       /* But preserve unsignedness from the other type,
  305.          since long cannot hold all the values of an unsigned int.  */
  306.       if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
  307.         return long_unsigned_type_node;
  308.       return long_integer_type_node;
  309.     }
  310.  
  311.       /* Otherwise prefer the unsigned one.  */
  312.  
  313.       if (TREE_UNSIGNED (t1))
  314.     return t1;
  315.       else return t2;
  316.  
  317.     case POINTER_TYPE:
  318.     case REFERENCE_TYPE:
  319.       /* For two pointers, do this recursively on the target type,
  320.      and combine the qualifiers of the two types' targets.  */
  321.       /* This code was turned off; I don't know why.
  322.       But ANSI C++ specifies doing this with the qualifiers.
  323.       So I turned it on again.  */
  324.       {
  325.     tree target = common_type (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
  326.                    TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
  327.     int constp
  328.       = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
  329.     int volatilep
  330.       = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
  331.     target = build_type_variant (target, constp, volatilep);
  332.     if (code1 == POINTER_TYPE)
  333.       return build_pointer_type (target);
  334.     else
  335.       return build_reference_type (target);
  336.       }
  337. #if 0
  338.     case POINTER_TYPE:
  339.       return build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  340.  
  341.     case REFERENCE_TYPE:
  342.       return build_reference_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  343. #endif
  344.  
  345.     case ARRAY_TYPE:
  346.       {
  347.     tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  348.     /* Save space: see if the result is identical to one of the args.  */
  349.     if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
  350.       return t1;
  351.     if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
  352.       return t2;
  353.     /* Merge the element types, and have a size if either arg has one.  */
  354.     return build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
  355.       }
  356.  
  357.     case FUNCTION_TYPE:
  358.       /* Function types: prefer the one that specified arg types.
  359.      If both do, merge the arg types.  Also merge the return types.  */
  360.       {
  361.     tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  362.     tree p1 = TYPE_ARG_TYPES (t1);
  363.     tree p2 = TYPE_ARG_TYPES (t2);
  364.     tree rval, raises;
  365.  
  366.     /* Save space: see if the result is identical to one of the args.  */
  367.     if (valtype == TREE_TYPE (t1) && ! p2)
  368.       return t1;
  369.     if (valtype == TREE_TYPE (t2) && ! p1)
  370.       return t2;
  371.  
  372.     /* Simple way if one arg fails to specify argument types.  */
  373.     if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
  374.       {
  375.         rval = build_function_type (valtype, p2);
  376.         if (raises = TYPE_RAISES_EXCEPTIONS (t2))
  377.           rval = build_exception_variant (NULL_TREE, rval, raises);
  378.         return rval;
  379.       }
  380.     raises = TYPE_RAISES_EXCEPTIONS (t1);
  381.     if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
  382.       {
  383.         rval = build_function_type (valtype, p1);
  384.         if (raises)
  385.           rval = build_exception_variant (NULL_TREE, rval, raises);
  386.         return rval;
  387.       }
  388.  
  389.     rval = build_function_type (valtype, commonparms (p1, p2));
  390.     return build_exception_variant (NULL_TREE, rval, raises);
  391.       }
  392.  
  393.     case RECORD_TYPE:
  394.     case UNION_TYPE:
  395.       my_friendly_assert (TYPE_MAIN_VARIANT (t1) == t1
  396.               && TYPE_MAIN_VARIANT (t2) == t2, 306);
  397.  
  398.       if (binfo_or_else (t1, t2))
  399.     return t1;
  400.       compiler_error ("common_type called with uncommon aggregate types");
  401.       return t1;
  402.  
  403.     case METHOD_TYPE:
  404.       if (TYPE_METHOD_BASETYPE (t1) == TYPE_METHOD_BASETYPE (t2)
  405.       && TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)))
  406.     {
  407.       /* Get this value the long way, since TYPE_METHOD_BASETYPE
  408.          is just the main variant of this.  */
  409.       tree basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1)));
  410.       tree raises, t3;
  411.  
  412.       raises = TYPE_RAISES_EXCEPTIONS (t1);
  413.  
  414.       /* If this was a member function type, get back to the
  415.          original type of type member function (i.e., without
  416.          the class instance variable up front.  */
  417.       t1 = build_function_type (TREE_TYPE (t1), TREE_CHAIN (TYPE_ARG_TYPES (t1)));
  418.       t2 = build_function_type (TREE_TYPE (t2), TREE_CHAIN (TYPE_ARG_TYPES (t2)));
  419.       t3 = common_type (t1, t2);
  420.       t3 = build_cplus_method_type (basetype, TREE_TYPE (t3), TYPE_ARG_TYPES (t3));
  421.       return build_exception_variant (basetype, t3, raises);
  422.     }
  423.       compiler_error ("common_type called with uncommon method types");
  424.       return t1;
  425.  
  426.     case OFFSET_TYPE:
  427.       if (TYPE_OFFSET_BASETYPE (t1) == TYPE_OFFSET_BASETYPE (t2)
  428.       && TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)))
  429.     {
  430.       tree basetype = TYPE_OFFSET_BASETYPE (t1);
  431.       return build_offset_type (basetype,
  432.                     common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  433.     }
  434.       compiler_error ("common_type called with uncommon member types");
  435.       return t1;
  436.  
  437.     default:
  438.       return t1;
  439.     }
  440. }
  441.  
  442. /* Return 1 if TYPE1 and TYPE2 raise the same exceptions.  */
  443. int
  444. compexcepttypes (t1, t2, strict)
  445.      tree t1, t2;
  446.      int strict;
  447. {
  448.   return TYPE_RAISES_EXCEPTIONS (t1) == TYPE_RAISES_EXCEPTIONS (t2);
  449. }
  450.  
  451. static int
  452. comp_array_types (cmp, t1, t2, strict)
  453.      register int (*cmp)();
  454.      tree t1, t2;
  455.      int strict;
  456. {
  457.   tree d1 = TYPE_DOMAIN (t1);
  458.   tree d2 = TYPE_DOMAIN (t2);
  459.  
  460.   /* Target types must match incl. qualifiers.  */
  461.   if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
  462.     || (*cmp) (TREE_TYPE (t1), TREE_TYPE (t2), strict)))
  463.     return 0;
  464.  
  465.   /* Sizes must match unless one is missing or variable.  */
  466.   if (d1 == 0 || d2 == 0 || d1 == d2
  467.       || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
  468.       || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
  469.       || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
  470.       || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
  471.     return 1;
  472.  
  473.   return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
  474.        == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
  475.       && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
  476.           == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
  477.       && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
  478.           == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
  479.       && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
  480.           == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))));
  481. }
  482.  
  483. /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
  484.    or various other operations.  This is what ANSI C++ speaks of as
  485.    "being the same".
  486.  
  487.    For C++: argument STRICT says we should be strict about this
  488.    comparison:
  489.  
  490.     2 : strict, except that if one type is a reference and
  491.         the other is not, compare the target type of the
  492.         reference to the type that's not a reference (ARM, p308).
  493.     1 : strict (compared according to ANSI C)
  494.     0 : <= (compared according to C++)
  495.     -1: <= or >= (relaxed)
  496.  
  497.    Otherwise, pointers involving base classes and derived classes
  498.    can be mixed as legal: i.e. a pointer to a base class may be assigned
  499.    to a pointer to one of its derived classes, as per C++. A pointer to
  500.    a derived class may be passed as a parameter to a function expecting a
  501.    pointer to a base classes. These allowances do not commute. In this
  502.    case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
  503.    be the derived class.  */
  504. int
  505. comptypes (type1, type2, strict)
  506.      tree type1, type2;
  507.      int strict;
  508. {
  509.   register tree t1 = type1;
  510.   register tree t2 = type2;
  511.  
  512.   /* Suppress errors caused by previously reported errors */
  513.  
  514.   if (t1 == t2)
  515.     return 1;
  516.  
  517.   /* This should never happen.  */
  518.   my_friendly_assert (t1 != error_mark_node, 307);
  519.  
  520.   if (t2 == error_mark_node)
  521.     return 0;
  522.  
  523.   if (strict < 0)
  524.     {
  525.       /* Treat an enum type as the unsigned integer type of the same width.  */
  526.  
  527.       if (TREE_CODE (t1) == ENUMERAL_TYPE)
  528.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  529.       if (TREE_CODE (t2) == ENUMERAL_TYPE)
  530.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  531.     }
  532.  
  533.   if (t1 == t2)
  534.     return 1;
  535.  
  536.   /* Different classes of types can't be compatible.  */
  537.  
  538.   if (TREE_CODE (t1) != TREE_CODE (t2))
  539.     {
  540.       if (strict == 2
  541.       && ((TREE_CODE (t1) == REFERENCE_TYPE)
  542.           ^ (TREE_CODE (t2) == REFERENCE_TYPE)))
  543.     {
  544.       if (TREE_CODE (t1) == REFERENCE_TYPE)
  545.         return comptypes (TREE_TYPE (t1), t2, 1);
  546.       return comptypes (t1, TREE_TYPE (t2), 1);
  547.     }
  548.  
  549.       return 0;
  550.     }
  551.   if (strict > 1)
  552.     strict = 1;
  553.  
  554.   /* Qualifiers must match.  */
  555.  
  556.   if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
  557.     return 0;
  558.   if (TREE_THIS_VOLATILE (t1) != TREE_THIS_VOLATILE (t2))
  559.     return 0;
  560.  
  561.   /* Allow for two different type nodes which have essentially the same
  562.      definition.  Note that we already checked for equality of the type
  563.      type qualifiers (just above).  */
  564.  
  565.   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
  566.     return 1;
  567.  
  568.   switch (TREE_CODE (t1))
  569.     {
  570.     case RECORD_TYPE:
  571.     case UNION_TYPE:
  572.       if (t1 == t2)
  573.     return 1;
  574. #ifdef OBJCPLUS
  575.       if (maybe_objc_comptypes (t1, t2, 0) == 1)
  576.          return 1;
  577. #endif
  578.       if (strict <= 0)
  579.     goto look_hard;
  580.       return 0;
  581.  
  582.     case OFFSET_TYPE:
  583.       return (comptypes (TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t1)),
  584.              TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t2)), strict)
  585.           && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict));
  586.  
  587.     case METHOD_TYPE:
  588.       if (! compexcepttypes (t1, t2, strict))
  589.     return 0;
  590.  
  591.       /* This case is anti-symmetrical!
  592.      One can pass a base member (or member function)
  593.      to something expecting a derived member (or member function),
  594.      but not vice-versa!  */
  595.  
  596.       return (comptypes (TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t2)),
  597.              TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t1)), strict)
  598.           && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)
  599.           && compparms (TREE_CHAIN (TYPE_ARG_TYPES (t1)),
  600.                 TREE_CHAIN (TYPE_ARG_TYPES(t2)), strict));
  601.     case POINTER_TYPE:
  602.     case REFERENCE_TYPE:
  603.       t1 = TREE_TYPE (t1);
  604.       t2 = TREE_TYPE (t2);
  605.       if (t1 == t2)
  606.     return 1;
  607.       if (strict <= 0)
  608.     {
  609. #ifdef OBJCPLUS
  610.           if (maybe_objc_comptypes (t1, t2, 0) == 1)
  611.         return 1;
  612. #endif /* OBJCPLUS */
  613.       if (TREE_CODE (t1) == RECORD_TYPE && TREE_CODE (t2) == RECORD_TYPE)
  614.         {
  615.           int rval;
  616.         look_hard:
  617.           rval = t1 == t2 || UNIQUELY_DERIVED_FROM_P (t1, t2);
  618.  
  619.           if (rval)
  620.         return 1;
  621.           if (strict < 0)
  622.         return UNIQUELY_DERIVED_FROM_P (t2, t1);
  623.         }
  624.       return 0;
  625.     }
  626.       else
  627.     return comptypes (t1, t2, strict);
  628.  
  629.     case FUNCTION_TYPE:
  630.       if (! compexcepttypes (t1, t2, strict))
  631.     return 0;
  632.  
  633.       return ((TREE_TYPE (t1) == TREE_TYPE (t2)
  634.            || comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict))
  635.           && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2), strict));
  636.  
  637.     case ARRAY_TYPE:
  638.       /* Target types must match incl. qualifiers.  */
  639.       return comp_array_types (comptypes, t1, t2, strict);
  640.  
  641.     }
  642.   return 0;
  643. }
  644.  
  645. /* Return 1 if TTL and TTR are pointers to types that are equivalent,
  646.    ignoring their qualifiers.
  647.  
  648.    NPTRS is the number of pointers we can strip off and keep cool.
  649.    This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
  650.    but to not permit B** to convert to A**.  */
  651.  
  652. int
  653. comp_target_types (ttl, ttr, nptrs)
  654.      tree ttl, ttr;
  655.      int nptrs;
  656. {
  657.   ttl = TYPE_MAIN_VARIANT (ttl);
  658.   ttr = TYPE_MAIN_VARIANT (ttr);
  659.  
  660.   if (ttl == ttr)
  661.     return 1;
  662.  
  663. #ifdef OBJCPLUS
  664.  /* emits warnings as appropriate */
  665.   if (maybe_objc_comptypes (ttl, ttr, 1) == 1)
  666.     return 1;
  667. #endif /* OBJCPLUS */
  668.  
  669.   if (TREE_CODE (ttr) != TREE_CODE (ttl))
  670.     return 0;
  671.  
  672.   if (TREE_CODE (ttr) == POINTER_TYPE)
  673.     return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs - 1);
  674.  
  675.   if (TREE_CODE (ttr) == REFERENCE_TYPE)
  676.     return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
  677.   if (TREE_CODE (ttr) == ARRAY_TYPE)
  678.     return comp_array_types (comp_target_types, ttl, ttr, 0);
  679.   else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
  680.     if (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
  681.       switch (comp_target_parms (TYPE_ARG_TYPES (ttl), TYPE_ARG_TYPES (ttr), 0))
  682.     {
  683.     case 0:
  684.       return 0;
  685.     case 1:
  686.       return 1;
  687.     case 2:
  688.       warning ("contravariance violation for method types ignored");
  689.       return 1;
  690.     default:
  691.       my_friendly_abort (112);
  692.     }
  693.     else
  694.       return 0;
  695.  
  696.   /* for C++ */
  697.   else if (TREE_CODE (ttr) == OFFSET_TYPE)
  698.     {
  699.       /* Contravariance: we can assign a pointer to base member to a pointer
  700.      to derived member.  Note difference from simple pointer case, where
  701.      we can pass a pointer to derived to a pointer to base.  */
  702.       if (comptypes (TYPE_OFFSET_BASETYPE (ttr), TYPE_OFFSET_BASETYPE (ttl), 0))
  703.     return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
  704.       else if (comptypes (TYPE_OFFSET_BASETYPE (ttl), TYPE_OFFSET_BASETYPE (ttr), 0)
  705.            && comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
  706.     {
  707.       warning ("contravariance violation for member types ignored");
  708.       return 1;
  709.     }
  710.     }
  711.   else if (IS_AGGR_TYPE (ttl))
  712.     {
  713.       if (nptrs < 0)
  714.     return 0;
  715.       return comptypes (TYPE_POINTER_TO (ttl), TYPE_POINTER_TO (ttr), 0);
  716.     }
  717.  
  718.   return 0;
  719. }
  720.  
  721. /* If two types share a common base type, return that basetype.
  722.    If there is not a unique most-derived base type, this function
  723.    returns ERROR_MARK_NODE.  */
  724. tree
  725. common_base_type (tt1, tt2)
  726.      tree tt1, tt2;
  727. {
  728.   tree best = NULL_TREE, tmp;
  729.   int i;
  730.  
  731.   /* If one is a baseclass of another, that's good enough.  */
  732.   if (UNIQUELY_DERIVED_FROM_P (tt1, tt2))
  733.     return tt1;
  734.   if (UNIQUELY_DERIVED_FROM_P (tt2, tt1))
  735.     return tt2;
  736.  
  737.   /* If they share a virtual baseclass, that's good enough.  */
  738.   for (tmp = CLASSTYPE_VBASECLASSES (tt1); tmp; tmp = TREE_CHAIN (tmp))
  739.     {
  740.       if (binfo_member (BINFO_TYPE (tmp), CLASSTYPE_VBASECLASSES (tt2)))
  741.     return BINFO_TYPE (tmp);
  742.     }
  743.  
  744.   /* Otherwise, try to find a unique baseclass of TT1
  745.      that is shared by TT2, and follow that down.  */
  746.   for (i = CLASSTYPE_N_BASECLASSES (tt1)-1; i >= 0; i--)
  747.     {
  748.       tree basetype = TYPE_BINFO_BASETYPE (tt1, i);
  749.       tree trial = common_base_type (basetype, tt2);
  750.       if (trial)
  751.     {
  752.       if (trial == error_mark_node)
  753.         return trial;
  754.       if (best == NULL_TREE)
  755.         best = trial;
  756.       else if (best != trial)
  757.         return error_mark_node;
  758.     }
  759.     }
  760.  
  761.   /* Same for TT2.  */
  762.   for (i = CLASSTYPE_N_BASECLASSES (tt2)-1; i >= 0; i--)
  763.     {
  764.       tree basetype = TYPE_BINFO_BASETYPE (tt2, i);
  765.       tree trial = common_base_type (tt1, basetype);
  766.       if (trial)
  767.     {
  768.       if (trial == error_mark_node)
  769.         return trial;
  770.       if (best == NULL_TREE)
  771.         best = trial;
  772.       else if (best != trial)
  773.         return error_mark_node;
  774.     }
  775.     }
  776.   return best;
  777. }
  778.  
  779. /* Subroutines of `comptypes'.  */
  780.  
  781. /* Return 1 if two parameter type lists PARMS1 and PARMS2
  782.    are equivalent in the sense that functions with those parameter types
  783.    can have equivalent types.
  784.    If either list is empty, we win.
  785.    Otherwise, the two lists must be equivalent, element by element.
  786.  
  787.    C++: See comment above about TYPE1, TYPE2, STRICT.
  788.    If STRICT == 3, it means checking is strict, but do not compare
  789.    default parameter values.  */
  790. int
  791. compparms (parms1, parms2, strict)
  792.      tree parms1, parms2;
  793.      int strict;
  794. {
  795.   register tree t1 = parms1, t2 = parms2;
  796.  
  797.   /* An unspecified parmlist matches any specified parmlist
  798.      whose argument types don't need default promotions.  */
  799.  
  800.   if (t1 == 0)
  801.     return self_promoting_args_p (t2);
  802.   if (t2 == 0)
  803.     return self_promoting_args_p (t1);
  804.  
  805.   while (1)
  806.     {
  807.       if (t1 == 0 && t2 == 0)
  808.     return 1;
  809.       /* If one parmlist is shorter than the other,
  810.      they fail to match, unless STRICT is <= 0.  */
  811.       if (t1 == 0 || t2 == 0)
  812.     {
  813.       if (strict > 0)
  814.         return 0;
  815.       if (strict < 0)
  816.         return 1;
  817.       if (strict == 0)
  818.         return t1 && TREE_PURPOSE (t1);
  819.     }
  820.       if (! comptypes (TREE_VALUE (t2), TREE_VALUE (t1), strict))
  821.     {
  822.       if (strict > 0)
  823.         return 0;
  824.       if (strict == 0)
  825.         return t2 == void_list_node && TREE_PURPOSE (t1);
  826.       return TREE_PURPOSE (t1) || TREE_PURPOSE (t2);
  827.     }
  828.       if (strict != 3 && TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
  829.     {
  830.       int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
  831.       if (cmp < 0)
  832.         my_friendly_abort (113);
  833.       if (cmp == 0)
  834.         return 0;
  835.     }
  836.  
  837.       t1 = TREE_CHAIN (t1);
  838.       t2 = TREE_CHAIN (t2);
  839.     }
  840. }
  841.  
  842. /* This really wants return whether or not parameter type lists
  843.    would make their owning functions assignment compatible or not.  */
  844. int
  845. comp_target_parms (parms1, parms2, strict)
  846.      tree parms1, parms2;
  847.      int strict;
  848. {
  849.   register tree t1 = parms1, t2 = parms2;
  850.   int warn_contravariance = 0;
  851.  
  852.   /* An unspecified parmlist matches any specified parmlist
  853.      whose argument types don't need default promotions.
  854.      @@@ see 13.3.3 for a counterexample...  */
  855.  
  856.   if (t1 == 0 && t2 != 0)
  857.     {
  858.       cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
  859.           parms2);
  860.       return self_promoting_args_p (t2);
  861.     }
  862.   if (t2 == 0)
  863.     return self_promoting_args_p (t1);
  864.  
  865.   for (; t1 || t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
  866.     {
  867.       tree p1, p2;
  868.  
  869.       /* If one parmlist is shorter than the other,
  870.      they fail to match, unless STRICT is <= 0.  */
  871.       if (t1 == 0 || t2 == 0)
  872.     {
  873.       if (strict > 0)
  874.         return 0;
  875.       if (strict < 0)
  876.         return 1 + warn_contravariance;
  877.       return ((t1 && TREE_PURPOSE (t1)) + warn_contravariance);
  878.     }
  879.       p1 = TREE_VALUE (t1);
  880.       p2 = TREE_VALUE (t2);
  881.       if (p1 == p2)
  882.     continue;
  883.       if ((TREE_CODE (p1) == POINTER_TYPE && TREE_CODE (p2) == POINTER_TYPE)
  884.       || (TREE_CODE (p1) == REFERENCE_TYPE && TREE_CODE (p2) == REFERENCE_TYPE))
  885.     {
  886.       if (strict <= 0
  887.           && (TYPE_MAIN_VARIANT (TREE_TYPE (p1))
  888.           == TYPE_MAIN_VARIANT (TREE_TYPE (p2))))
  889.         continue;
  890.  
  891.       /* The following is wrong for contravariance,
  892.          but many programs depend on it.  */
  893.       if (TREE_TYPE (p1) == void_type_node)
  894.         continue;
  895.       if (TREE_TYPE (p2) == void_type_node)
  896.         {
  897.           warn_contravariance = 1;
  898.           continue;
  899.         }
  900.       if (IS_AGGR_TYPE (TREE_TYPE (p1)))
  901.         {
  902.           if (comptypes (p2, p1, 0) == 0)
  903.         {
  904.           if (comptypes (p1, p2, 0) != 0)
  905.             warn_contravariance = 1;
  906.           else
  907.             return 0;
  908.         }
  909.           continue;
  910.         }
  911.     }
  912.       /* Note backwards order due to contravariance.  */
  913.       if (comp_target_types (p2, p1, 1) == 0)
  914.     {
  915.       if (comp_target_types (p1, p2, 1))
  916.         {
  917.           warn_contravariance = 1;
  918.           continue;
  919.         }
  920.       if (strict != 0)
  921.         return 0;
  922. #if 0
  923.       /* What good do these cases do?  */
  924.       if (strict == 0)
  925.         return p2 == void_type_node && TREE_PURPOSE (t1);
  926.       return TREE_PURPOSE (t1) || TREE_PURPOSE (t2);
  927. #endif
  928.     }
  929.       /* Target types are compatible--just make sure that if
  930.      we use parameter lists, that they are ok as well.  */
  931.       if (TREE_CODE (p1) == FUNCTION_TYPE || TREE_CODE (p1) == METHOD_TYPE)
  932.     switch (comp_target_parms (TYPE_ARG_TYPES (p1),
  933.                    TYPE_ARG_TYPES (p2),
  934.                    strict))
  935.       {
  936.       case 0:
  937.         return 0;
  938.       case 1:
  939.         break;
  940.       case 2:
  941.         warn_contravariance = 1;
  942.       }
  943.  
  944.       if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
  945.     {
  946.       int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
  947.       if (cmp < 0)
  948.         my_friendly_abort (114);
  949.       if (cmp == 0)
  950.         return 0;
  951.     }
  952.     }
  953.   return 1 + warn_contravariance;
  954. }
  955.  
  956. /* Return 1 if PARMS specifies a fixed number of parameters
  957.    and none of their types is affected by default promotions.  */
  958.  
  959. static int
  960. self_promoting_args_p (parms)
  961.      tree parms;
  962. {
  963.   register tree t;
  964.   for (t = parms; t; t = TREE_CHAIN (t))
  965.     {
  966.       register tree type = TREE_VALUE (t);
  967.  
  968.       if (TREE_CHAIN (t) == 0 && type != void_type_node)
  969.     return 0;
  970.  
  971.       if (TYPE_MAIN_VARIANT (type) == float_type_node)
  972.     return 0;
  973.  
  974.       if (type == 0)
  975.     return 0;
  976.  
  977.       if (C_PROMOTING_INTEGER_TYPE_P (type))
  978.     return 0;
  979.     }
  980.   return 1;
  981. }
  982.  
  983. /* Return an unsigned type the same as TYPE in other respects.
  984.  
  985.    C++: must make these work for type variants as well.  */
  986.  
  987. tree
  988. unsigned_type (type)
  989.      tree type;
  990. {
  991.   tree type1 = TYPE_MAIN_VARIANT (type);
  992.   if (type1 == signed_char_type_node || type1 == char_type_node)
  993.     return unsigned_char_type_node;
  994.   if (type1 == integer_type_node)
  995.     return unsigned_type_node;
  996.   if (type1 == short_integer_type_node)
  997.     return short_unsigned_type_node;
  998.   if (type1 == long_integer_type_node)
  999.     return long_unsigned_type_node;
  1000.   if (type1 == long_long_integer_type_node)
  1001.     return long_long_unsigned_type_node;
  1002.   return type;
  1003. }
  1004.  
  1005. /* Return a signed type the same as TYPE in other respects.  */
  1006.  
  1007. tree
  1008. signed_type (type)
  1009.      tree type;
  1010. {
  1011.   tree type1 = TYPE_MAIN_VARIANT (type);
  1012.   if (type1 == unsigned_char_type_node || type1 == char_type_node)
  1013.     return signed_char_type_node;
  1014.   if (type1 == unsigned_type_node)
  1015.     return integer_type_node;
  1016.   if (type1 == short_unsigned_type_node)
  1017.     return short_integer_type_node;
  1018.   if (type1 == long_unsigned_type_node)
  1019.     return long_integer_type_node;
  1020.   if (type1 == long_long_unsigned_type_node)
  1021.     return long_long_integer_type_node;
  1022.   return type;
  1023. }
  1024.  
  1025. /* Return a type the same as TYPE except unsigned or
  1026.    signed according to UNSIGNEDP.  */
  1027.  
  1028. tree
  1029. signed_or_unsigned_type (unsignedp, type)
  1030.      int unsignedp;
  1031.      tree type;
  1032. {
  1033.   if (TREE_CODE (type) != INTEGER_TYPE)
  1034.     return type;
  1035.   if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
  1036.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  1037.   if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 
  1038.     return unsignedp ? unsigned_type_node : integer_type_node;
  1039.   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) 
  1040.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  1041.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) 
  1042.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  1043.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node)) 
  1044.     return (unsignedp ? long_long_unsigned_type_node
  1045.         : long_long_integer_type_node);
  1046.   return type;
  1047. }
  1048.  
  1049. tree
  1050. c_sizeof (type)
  1051.      tree type;
  1052. {
  1053.   enum tree_code code = TREE_CODE (type);
  1054.   tree t;
  1055.  
  1056.   if (code == FUNCTION_TYPE)
  1057.     {
  1058.       if (pedantic || warn_pointer_arith)
  1059.     pedwarn ("ANSI C++ forbids taking the sizeof a function type");
  1060.       return size_int (1);
  1061.     }
  1062.   if (code == METHOD_TYPE)
  1063.     {
  1064.       if (pedantic || warn_pointer_arith)
  1065.     pedwarn ("ANSI C++ forbids taking the sizeof a method type");
  1066.       return size_int (1);
  1067.     }
  1068.   if (code == VOID_TYPE)
  1069.     {
  1070.       if (pedantic || warn_pointer_arith)
  1071.     pedwarn ("ANSI C++ forbids taking the sizeof a void type");
  1072.       return size_int (1);
  1073.     }
  1074.   if (code == ERROR_MARK)
  1075.     return size_int (1);
  1076.  
  1077.   /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
  1078.      referenced object.'' */
  1079.   if (code == REFERENCE_TYPE)
  1080.     type = TREE_TYPE (type);
  1081.  
  1082.   /* We couldn't find anything in the ARM or the draft standard that says,
  1083.      one way or the other, if doing sizeof on something that doesn't have
  1084.      an object associated with it is correct or incorrect.  For example, if
  1085.      you declare `struct S { char str[16]; };', and in your program do
  1086.      a `sizeof (S::str)', should we flag that as an error or should we give
  1087.      the size of it?  Since it seems like a reasonable thing to do, we'll go
  1088.      with giving the value.  */
  1089.   if (code == OFFSET_TYPE)
  1090.     type = TREE_TYPE (type);
  1091.  
  1092.   if (TYPE_SIZE (type) == 0)
  1093.     {
  1094.       error ("sizeof applied to an incomplete type");
  1095.       return size_int (0);
  1096.     }
  1097.  
  1098.   /* Convert in case a char is more than one unit.  */
  1099.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  1100.           size_int (TYPE_PRECISION (char_type_node)));
  1101.   /* size_binop does not put the constant in range, so do it now.  */
  1102.   if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
  1103.     TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
  1104.   return t;
  1105. }
  1106.  
  1107. tree
  1108. c_sizeof_nowarn (type)
  1109.      tree type;
  1110. {
  1111.   enum tree_code code = TREE_CODE (type);
  1112.   tree t;
  1113.  
  1114.   if (code == FUNCTION_TYPE
  1115.       || code == METHOD_TYPE
  1116.       || code == VOID_TYPE
  1117.       || code == ERROR_MARK)
  1118.     return size_int (1);
  1119.   if (code == REFERENCE_TYPE)
  1120.     type = TREE_TYPE (type);
  1121.  
  1122.   if (TYPE_SIZE (type) == 0)
  1123.     {
  1124.       /* ??? Tiemann, why have any diagnostic here?
  1125.      There is none in the corresponding function for C.  */
  1126.       warning ("sizeof applied to an incomplete type");
  1127.       return size_int (0);
  1128.     }
  1129.  
  1130.   /* Convert in case a char is more than one unit.  */
  1131.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  1132.              size_int (TYPE_PRECISION (char_type_node)));
  1133.   force_fit_type (t, 0);
  1134.   return t;
  1135. }
  1136.  
  1137. /* Implement the __alignof keyword: Return the minimum required
  1138.    alignment of TYPE, measured in bytes.  */
  1139.  
  1140. tree
  1141. c_alignof (type)
  1142.      tree type;
  1143. {
  1144.   enum tree_code code = TREE_CODE (type);
  1145.   tree t;
  1146.  
  1147.   if (code == FUNCTION_TYPE || code == METHOD_TYPE)
  1148.     return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  1149.  
  1150.   if (code == VOID_TYPE || code == ERROR_MARK)
  1151.     return size_int (1);
  1152.  
  1153.   /* C++: this is really correct!  */
  1154.   if (code == REFERENCE_TYPE)
  1155.     type = TREE_TYPE (type);
  1156.  
  1157.   t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
  1158.   force_fit_type (t, 0);
  1159.   return t;
  1160. }
  1161.  
  1162. /* Perform default promotions for C data used in expressions.
  1163.    Arrays and functions are converted to pointers;
  1164.    enumeral types or short or char, to int.
  1165.    In addition, manifest constants symbols are replaced by their values.
  1166.  
  1167.    C++: this will automatically bash references to their target type.  */
  1168.  
  1169. tree
  1170. default_conversion (exp)
  1171.      tree exp;
  1172. {
  1173.   register tree type = TREE_TYPE (exp);
  1174.   register enum tree_code code = TREE_CODE (type);
  1175.  
  1176.   if (code == OFFSET_TYPE /* || TREE_CODE (exp) == OFFSET_REF */ )
  1177.     {
  1178.       if (TREE_CODE (exp) == OFFSET_REF)
  1179.     return default_conversion (resolve_offset_ref (exp));
  1180.  
  1181.       type = TREE_TYPE (type);
  1182.       code = TREE_CODE (type);
  1183.     }
  1184.  
  1185.   if (code == REFERENCE_TYPE)
  1186.     {
  1187.       exp = convert_from_reference (exp);
  1188.       type = TREE_TYPE (exp);
  1189.       code = TREE_CODE (type);
  1190.     }
  1191.  
  1192.   /* Constants can be used directly unless they're not loadable.  */
  1193.   if (TREE_CODE (exp) == CONST_DECL)
  1194.     exp = DECL_INITIAL (exp);
  1195.   /* Replace a nonvolatile const static variable with its value.  */
  1196.   else if (TREE_READONLY_DECL_P (exp) && DECL_MODE (exp) != BLKmode)
  1197.     {
  1198.       exp = decl_constant_value (exp);
  1199.       type = TREE_TYPE (exp);
  1200.     }
  1201.  
  1202.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  1203.      Leave such NOP_EXPRs, since RHS is being used in non-lvalue context.  */
  1204.  
  1205.   /* Normally convert enums to int,
  1206.      but convert wide enums to something wider.  */
  1207.   if (code == ENUMERAL_TYPE)
  1208.     {
  1209.       type = type_for_size (MAX (TYPE_PRECISION (type),
  1210.                  TYPE_PRECISION (integer_type_node)),
  1211.                 ((flag_traditional
  1212.                   || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node))
  1213.                  && TREE_UNSIGNED (type)));
  1214.       return convert (type, exp);
  1215.     }
  1216.  
  1217.   if (C_PROMOTING_INTEGER_TYPE_P (type))
  1218.     {
  1219.       /* Traditionally, unsignedness is preserved in default promotions.
  1220.          Otherwise, retain unsignedness if really not getting bigger.  */
  1221.       if (TREE_UNSIGNED (type)
  1222.       && (flag_traditional
  1223.           || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
  1224.     return convert (unsigned_type_node, exp);
  1225.       return convert (integer_type_node, exp);
  1226.     }
  1227.   if (flag_traditional
  1228.       && TYPE_MAIN_VARIANT (type) == float_type_node)
  1229.     return convert (double_type_node, exp);
  1230.   if (code == VOID_TYPE)
  1231.     {
  1232.       error ("void value not ignored as it ought to be");
  1233.       return error_mark_node;
  1234.     }
  1235.   if (code == FUNCTION_TYPE)
  1236.     {
  1237.       return build_unary_op (ADDR_EXPR, exp, 0);
  1238.     }
  1239.   if (code == METHOD_TYPE)
  1240.     {
  1241.       if (TREE_CODE (exp) == OFFSET_REF)
  1242.     {
  1243.       my_friendly_assert (TREE_CODE (TREE_OPERAND (exp, 1)) == FUNCTION_DECL,
  1244.                   308);
  1245.       return build_unary_op (ADDR_EXPR, TREE_OPERAND (exp, 1), 0);
  1246.     }
  1247.       return build_unary_op (ADDR_EXPR, exp, 0);
  1248.     }
  1249.   if (code == ARRAY_TYPE)
  1250.     {
  1251.       register tree adr;
  1252.       tree restype = TREE_TYPE (type);
  1253.       tree ptrtype;
  1254.  
  1255.       if (TREE_CODE (exp) == INDIRECT_REF)
  1256.     {
  1257.       /* Stripping away the INDIRECT_REF is not the right
  1258.          thing to do for references...  */
  1259.       tree inner = TREE_OPERAND (exp, 0);
  1260.       if (TREE_CODE (TREE_TYPE (inner)) == REFERENCE_TYPE)
  1261.         {
  1262.           inner = build1 (CONVERT_EXPR,
  1263.                   build_pointer_type (TREE_TYPE (TREE_TYPE (inner))),
  1264.                   inner);
  1265.           TREE_REFERENCE_EXPR (inner) = 1;
  1266.         }
  1267.       return convert (TYPE_POINTER_TO (TREE_TYPE (type)), inner);
  1268.     }
  1269.  
  1270.       if (TREE_CODE (exp) == COMPOUND_EXPR)
  1271.     {
  1272.       tree op1 = default_conversion (TREE_OPERAND (exp, 1));
  1273.       return build (COMPOUND_EXPR, TREE_TYPE (op1),
  1274.             TREE_OPERAND (exp, 0), op1);
  1275.     }
  1276.  
  1277.       if (!lvalue_p (exp)
  1278.       && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
  1279.     {
  1280.       error ("invalid use of non-lvalue array");
  1281.       return error_mark_node;
  1282.     }
  1283.  
  1284.       if (TYPE_READONLY (type) || TYPE_VOLATILE (type))
  1285.     restype = build_type_variant (restype, TYPE_READONLY (type),
  1286.                       TYPE_VOLATILE (type));
  1287.  
  1288.       ptrtype = build_pointer_type (restype);
  1289.  
  1290.       if (TREE_CODE (exp) == VAR_DECL)
  1291.     {
  1292.       /* ??? This is not really quite correct
  1293.          in that the type of the operand of ADDR_EXPR
  1294.          is not the target type of the type of the ADDR_EXPR itself.
  1295.          Question is, can this lossage be avoided?  */
  1296.       adr = build1 (ADDR_EXPR, ptrtype, exp);
  1297.       if (mark_addressable (exp) == 0)
  1298.         return error_mark_node;
  1299.       TREE_CONSTANT (adr) = staticp (exp);
  1300.       TREE_SIDE_EFFECTS (adr) = 0;   /* Default would be, same as EXP.  */
  1301.       return adr;
  1302.     }
  1303.       /* This way is better for a COMPONENT_REF since it can
  1304.      simplify the offset for a component.  */
  1305.       adr = build_unary_op (ADDR_EXPR, exp, 1);
  1306.       return convert (ptrtype, adr);
  1307.     }
  1308.   return exp;
  1309. }
  1310.  
  1311. tree
  1312. build_object_ref (datum, basetype, field)
  1313.      tree datum, basetype, field;
  1314. {
  1315.   if (is_aggr_typedef (basetype, 1) && datum != error_mark_node)
  1316.     {
  1317.       tree real_basetype = IDENTIFIER_TYPE_VALUE (basetype);
  1318.       if (binfo_or_else (real_basetype, TREE_TYPE (datum)))
  1319.     return build_component_ref (build_scoped_ref (datum, basetype),
  1320.                     field, NULL_TREE, 1);
  1321.     }
  1322.   return error_mark_node;
  1323. }
  1324.  
  1325. /* Like `build_component_ref, but uses an already found field.
  1326.    Must compute visibility for C_C_D.  Otherwise, ok.  */
  1327. tree
  1328. build_component_ref_1 (datum, field, protect)
  1329.      tree datum, field;
  1330.      int protect;
  1331. {
  1332.   register tree basetype = TREE_TYPE (datum);
  1333.   register enum tree_code code = TREE_CODE (basetype);
  1334.   register tree ref;
  1335.  
  1336.   if (code == REFERENCE_TYPE)
  1337.     {
  1338.       datum = convert_from_reference (datum);
  1339.       basetype = TREE_TYPE (datum);
  1340.       code = TREE_CODE (basetype);
  1341.     }
  1342.  
  1343.   if (! IS_AGGR_TYPE_CODE (code))
  1344.     {
  1345.       if (code != ERROR_MARK)
  1346.     cp_error ("request for member `%D' in something not a class, structure or union", field);
  1347.       return error_mark_node;
  1348.     }
  1349.  
  1350.   if (TYPE_SIZE (basetype) == 0)
  1351.     {
  1352.       incomplete_type_error (0, basetype);
  1353.       return error_mark_node;
  1354.     }
  1355.  
  1356.   /* Look up component name in the structure type definition.  */
  1357.  
  1358.   if (field == error_mark_node)
  1359.     my_friendly_abort (115);
  1360.  
  1361.   if (TREE_STATIC (field))
  1362.     return field;
  1363.  
  1364.   if (datum == C_C_D && ! DECL_PUBLIC (field))
  1365.     {
  1366.       enum visibility_type visibility
  1367.     = compute_visibility (TYPE_BINFO (current_class_type), field);
  1368.  
  1369.     if (visibility == visibility_private)
  1370.       {
  1371.     cp_error ("field `%D' is private", field);
  1372.     return error_mark_node;
  1373.       }
  1374.     else if (visibility == visibility_protected)
  1375.       {
  1376.     cp_error ("field `%D' is protected", field);
  1377.     return error_mark_node;
  1378.       }
  1379.     }
  1380.  
  1381.   ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
  1382.  
  1383.   if (TREE_READONLY (datum) || TREE_READONLY (field))
  1384.     TREE_READONLY (ref) = 1;
  1385.   if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
  1386.     TREE_THIS_VOLATILE (ref) = 1;
  1387.   if (DECL_MUTABLE_P (field))
  1388.     TREE_READONLY (ref) = 0;
  1389.  
  1390.   return ref;
  1391. }
  1392.  
  1393. tree
  1394. build_component_ref (datum, component, basetype_path, protect)
  1395.      tree datum, component, basetype_path;
  1396.      int protect;
  1397. {
  1398.   register tree basetype = TREE_TYPE (datum);
  1399.   register enum tree_code code = TREE_CODE (basetype);
  1400.   register tree field = NULL;
  1401.   register tree ref;
  1402.  
  1403.   /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
  1404.      unless we are not to support things not strictly ANSI.  */
  1405.   switch (TREE_CODE (datum))
  1406.     {
  1407.     case COMPOUND_EXPR:
  1408.       {
  1409.     tree value = build_component_ref (TREE_OPERAND (datum, 1), component,
  1410.                       basetype_path, protect);
  1411.     return build (COMPOUND_EXPR, TREE_TYPE (value),
  1412.               TREE_OPERAND (datum, 0), value);
  1413.       }
  1414.     case COND_EXPR:
  1415.       return build_conditional_expr
  1416.     (TREE_OPERAND (datum, 0),
  1417.      build_component_ref (TREE_OPERAND (datum, 1), component,
  1418.                   basetype_path, protect),
  1419.      build_component_ref (TREE_OPERAND (datum, 2), component,
  1420.                   basetype_path, protect));
  1421.     }
  1422.  
  1423.   if (code == REFERENCE_TYPE)
  1424.     {
  1425. #if 0
  1426.       /* TREE_REFERENCE_EXPRs are not converted by `convert_from_reference'.
  1427.      @@ Maybe that is not right.  */
  1428.       if (TREE_REFERENCE_EXPR (datum))
  1429.     datum = build1 (INDIRECT_REF, TREE_TYPE (basetype), datum);
  1430.       else
  1431. #endif
  1432.     datum = convert_from_reference (datum);
  1433.       basetype = TREE_TYPE (datum);
  1434.       code = TREE_CODE (basetype);
  1435.     }
  1436.  
  1437.   /* First, see if there is a field or component with name COMPONENT. */
  1438.   if (TREE_CODE (component) == TREE_LIST)
  1439.     {
  1440.       my_friendly_assert (!(TREE_CHAIN (component) == NULL_TREE
  1441.         && DECL_CHAIN (TREE_VALUE (component)) == NULL_TREE), 309);
  1442.       return build (COMPONENT_REF, TREE_TYPE (component), datum, component);
  1443.     }
  1444.   if (TREE_CODE (component) == TYPE_EXPR)
  1445.     return build_component_type_expr (datum, component, NULL_TREE, protect);
  1446.  
  1447.   if (! IS_AGGR_TYPE_CODE (code))
  1448.     {
  1449.       if (code != ERROR_MARK)
  1450.     error ("request for member `%s' in something not a class, structure or union",
  1451.            IDENTIFIER_POINTER (component));
  1452.       return error_mark_node;
  1453.     }
  1454.  
  1455.   if (TYPE_SIZE (basetype) == 0)
  1456.     {
  1457.       incomplete_type_error (0, basetype);
  1458.       return error_mark_node;
  1459.     }
  1460.  
  1461.   if (TREE_CODE (component) == BIT_NOT_EXPR)
  1462.     {
  1463.       if (TYPE_IDENTIFIER (basetype) != TREE_OPERAND (component, 0))
  1464.     {
  1465.       cp_error ("destructor specifier `%T::~%T' must have matching names",
  1466.             basetype, TREE_OPERAND (component, 0));
  1467.       return error_mark_node;
  1468.     }
  1469.       if (! TYPE_HAS_DESTRUCTOR (basetype))
  1470.     {
  1471.       cp_error ("type `%T' has no destructor", basetype);
  1472.       return error_mark_node;
  1473.     }
  1474.       return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0);
  1475.     }
  1476.  
  1477.   /* Look up component name in the structure type definition.  */
  1478.   if (CLASSTYPE_VFIELD (basetype)
  1479.       && DECL_NAME (CLASSTYPE_VFIELD (basetype)) == component)
  1480.     /* Special-case this because if we use normal lookups in an ambiguous
  1481.        hierarchy, the compiler will abort (because vptr lookups are
  1482.        not supposed to be ambiguous.  */
  1483.     field = CLASSTYPE_VFIELD (basetype);
  1484.   else
  1485.     {
  1486.       if (basetype_path == NULL_TREE)
  1487.     basetype_path = TYPE_BINFO (basetype);
  1488.       field = lookup_field (basetype_path, component,
  1489.                 protect && ! VFIELD_NAME_P (component), 0);
  1490.       if (field == error_mark_node)
  1491.     return error_mark_node;
  1492.  
  1493.       if (field == NULL_TREE)
  1494.     {
  1495.       /* Not found as a data field, look for it as a method.  If found,
  1496.          then if this is the only possible one, return it, else
  1497.          report ambiguity error.  */
  1498.       tree fndecls = lookup_fnfields (basetype_path, component, 1);
  1499.       if (fndecls == error_mark_node)
  1500.         return error_mark_node;
  1501.       if (fndecls)
  1502.         {
  1503.           if (TREE_CHAIN (fndecls) == NULL_TREE
  1504.           && DECL_CHAIN (TREE_VALUE (fndecls)) == NULL_TREE)
  1505.         {
  1506.           enum visibility_type visibility;
  1507.           tree fndecl;
  1508.  
  1509.           /* Unique, so use this one now.  */
  1510.           basetype = TREE_PURPOSE (fndecls);
  1511.           fndecl = TREE_VALUE (fndecls);
  1512.           visibility = compute_visibility (TREE_PURPOSE (fndecls), fndecl);
  1513.           if (visibility == visibility_public)
  1514.             {
  1515.               if (DECL_VINDEX (fndecl)
  1516.               && ! resolves_to_fixed_type_p (datum, 0))
  1517.             {
  1518.               tree addr = build_unary_op (ADDR_EXPR, datum, 0);
  1519.               addr = convert_pointer_to (DECL_CONTEXT (fndecl), addr);
  1520.               datum = build_indirect_ref (addr, NULL_PTR);
  1521.               my_friendly_assert (datum != error_mark_node, 310);
  1522.               fndecl = build_vfn_ref (&addr, datum, DECL_VINDEX (fndecl));
  1523.             }
  1524.               return fndecl;
  1525.             }
  1526.           if (visibility == visibility_protected)
  1527.             cp_error ("member function `%D' is protected", fndecl);
  1528.           else
  1529.             cp_error ("member function `%D' is private", fndecl);
  1530.           return error_mark_node;
  1531.         }
  1532.           else
  1533.         return build (COMPONENT_REF, unknown_type_node, datum, fndecls);
  1534.         }
  1535.  
  1536.       if (component == ansi_opname[(int) TYPE_EXPR])
  1537.         cp_error ("`%#T' has no such type conversion operator", basetype);
  1538.       else
  1539.         cp_error ("`%#T' has no member named `%D'", basetype, component);
  1540.       return error_mark_node;
  1541.     }
  1542.       else if (TREE_TYPE (field) == error_mark_node)
  1543.     return error_mark_node;
  1544.  
  1545.       if (TREE_CODE (field) != FIELD_DECL)
  1546.     {
  1547.       if (TREE_CODE (field) == TYPE_DECL)
  1548.         {
  1549.           error ("invalid use of type decl `%s' as expression",
  1550.              IDENTIFIER_POINTER (DECL_NAME (field)));
  1551.           return error_mark_node;
  1552.         }
  1553.        if (DECL_RTL (field) != 0)
  1554.         assemble_external (field);
  1555.       TREE_USED (field) = 1;
  1556.       return field;
  1557.     }
  1558.     }
  1559.  
  1560.   if (DECL_FIELD_CONTEXT (field) != basetype
  1561.       && TYPE_USES_COMPLEX_INHERITANCE (basetype))
  1562.     {
  1563.       tree addr = build_unary_op (ADDR_EXPR, datum, 0);
  1564.       if (integer_zerop (addr))
  1565.     {
  1566.       error ("invalid reference to NULL ptr, use ptr-to-member instead");
  1567.       return error_mark_node;
  1568.     }
  1569.       addr = convert_pointer_to (DECL_FIELD_CONTEXT (field), addr);
  1570.       datum = build_indirect_ref (addr, NULL_PTR);
  1571.       my_friendly_assert (datum != error_mark_node, 311);
  1572.     }
  1573.   ref = build (COMPONENT_REF, TREE_TYPE (field), break_out_cleanups (datum), field);
  1574.  
  1575.   if (TREE_READONLY (datum) || TREE_READONLY (field))
  1576.     TREE_READONLY (ref) = 1;
  1577.   if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
  1578.     TREE_THIS_VOLATILE (ref) = 1;
  1579.   if (DECL_MUTABLE_P (field))
  1580.     TREE_READONLY (ref) = 0;
  1581.  
  1582.   return ref;
  1583. }
  1584.  
  1585. /* Given an expression PTR for a pointer, return an expression
  1586.    for the value pointed to.
  1587.    ERRORSTRING is the name of the operator to appear in error messages.
  1588.  
  1589.    This function may need to overload OPERATOR_FNNAME.
  1590.    Must also handle REFERENCE_TYPEs for C++.  */
  1591.  
  1592. tree
  1593. build_x_indirect_ref (ptr, errorstring)
  1594.      tree ptr;
  1595.      char *errorstring;
  1596. {
  1597.   tree rval = build_opfncall (INDIRECT_REF, LOOKUP_NORMAL, ptr, NULL_TREE, NULL_TREE);
  1598.  
  1599.   if (rval) return rval;
  1600.   return build_indirect_ref (ptr, errorstring);
  1601. }
  1602.  
  1603. tree
  1604. build_indirect_ref (ptr, errorstring)
  1605.      tree ptr;
  1606.      char *errorstring;
  1607. {
  1608.   register tree pointer = default_conversion (ptr);
  1609.   register tree type = TREE_TYPE (pointer);
  1610.  
  1611.   if (ptr == current_class_decl)
  1612.     return C_C_D;
  1613.  
  1614.   if (TREE_CODE (type) == POINTER_TYPE || TREE_CODE (type) == REFERENCE_TYPE)
  1615.     {
  1616.       if (TREE_CODE (pointer) == ADDR_EXPR
  1617.       && (TREE_TYPE (TREE_OPERAND (pointer, 0))
  1618.           == TREE_TYPE (type)))
  1619.     return TREE_OPERAND (pointer, 0);
  1620.       else
  1621.     {
  1622.       tree t = TREE_TYPE (type);
  1623.       register tree ref = build1 (INDIRECT_REF,
  1624.                       TYPE_MAIN_VARIANT (t), pointer);
  1625.  
  1626.       TREE_READONLY (ref) = TYPE_READONLY (t);
  1627.       TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
  1628.       TREE_SIDE_EFFECTS (ref)
  1629.         = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
  1630.       return ref;
  1631.     }
  1632.     }
  1633.   /* `pointer' won't be an error_mark_node if we were given a
  1634.      pointer to member, so it's cool to check for this here.  */
  1635.   else if (TYPE_PTRMEMFUNC_P (type))
  1636.     error ("use of `%s' on pointer to member", errorstring);
  1637.   else if (pointer != error_mark_node)
  1638.     {
  1639.       if (errorstring)
  1640.     error ("invalid type argument of `%s'", errorstring);
  1641.       else
  1642.     error ("invalid type argument");
  1643.     }
  1644.   return error_mark_node;
  1645. }
  1646.  
  1647. /* This handles expressions of the form "a[i]", which denotes
  1648.    an array reference.
  1649.  
  1650.    This is logically equivalent in C to *(a+i), but we may do it differently.
  1651.    If A is a variable or a member, we generate a primitive ARRAY_REF.
  1652.    This avoids forcing the array out of registers, and can work on
  1653.    arrays that are not lvalues (for example, members of structures returned
  1654.    by functions).
  1655.  
  1656.    If INDEX is of some user-defined type, it must be converted to
  1657.    integer type.  Otherwise, to make a compatible PLUS_EXPR, it
  1658.    will inherit the type of the array, which will be some pointer type.  */
  1659.  
  1660. tree
  1661. build_x_array_ref (array, index)
  1662.      tree array, index;
  1663. {
  1664.   tree rval;
  1665.  
  1666.   rval = build_opfncall (ARRAY_REF, LOOKUP_NORMAL, array, index, NULL_TREE);
  1667.   if (rval)
  1668.     return rval;
  1669.   return build_array_ref (array, index);
  1670. }
  1671.  
  1672. tree
  1673. build_array_ref (array, idx)
  1674.      tree array, idx;
  1675. {
  1676.   tree itype;
  1677.  
  1678.   if (idx == 0)
  1679.     {
  1680.       error ("subscript missing in array reference");
  1681.       return error_mark_node;
  1682.     }
  1683.  
  1684.   if (TREE_TYPE (array) == error_mark_node
  1685.       || TREE_TYPE (idx) == error_mark_node)
  1686.     return error_mark_node;
  1687.  
  1688.   itype = TREE_TYPE (idx);
  1689.   /* We must check here for the reference, so we can do the possible
  1690.      conversions immediately afterwards.  */
  1691.   if (TREE_CODE (itype) == REFERENCE_TYPE)
  1692.     {
  1693.       idx = convert_from_reference (idx);
  1694.       itype = TREE_TYPE (idx);
  1695.     }
  1696.  
  1697.   if (IS_AGGR_TYPE (itype))
  1698.     {
  1699.       if (TYPE_HAS_INT_CONVERSION (itype))
  1700.     idx = build_type_conversion (CONVERT_EXPR,
  1701.                      integer_type_node, idx, 1);
  1702.       else
  1703.     {
  1704.       error_with_aggr_type (itype,
  1705.                 "type `%s' requires integer conversion for array indexing");
  1706.       return error_mark_node;
  1707.     }
  1708.     }
  1709.  
  1710.   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
  1711.       && TREE_CODE (array) != INDIRECT_REF)
  1712.     {
  1713.       tree rval, type;
  1714.  
  1715.       /* Subscripting with type char is likely to lose
  1716.      on a machine where chars are signed.
  1717.      So warn on any machine, but optionally.
  1718.      Don't warn for unsigned char since that type is safe.
  1719.      Don't warn for signed char because anyone who uses that
  1720.      must have done so deliberately.  */
  1721.       if (warn_char_subscripts
  1722.       && TYPE_MAIN_VARIANT (TREE_TYPE (idx)) == char_type_node)
  1723.     warning ("array subscript has type `char'");
  1724.  
  1725.       /* Apply default promotions *after* noticing character types.  */
  1726.       idx = default_conversion (idx);
  1727.  
  1728.       if (TREE_CODE (TREE_TYPE (idx)) != INTEGER_TYPE)
  1729.     {
  1730.       error ("array subscript is not an integer");
  1731.       return error_mark_node;
  1732.     }
  1733.  
  1734.       /* An array that is indexed by a non-constant
  1735.      cannot be stored in a register; we must be able to do
  1736.      address arithmetic on its address.
  1737.      Likewise an array of elements of variable size.  */
  1738.       if (TREE_CODE (idx) != INTEGER_CST
  1739.       || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
  1740.           && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
  1741.     {
  1742.       if (mark_addressable (array) == 0)
  1743.         return error_mark_node;
  1744.     }
  1745.       /* An array that is indexed by a constant value which is not within
  1746.      the array bounds cannot be stored in a register either; because we
  1747.      would get a crash in store_bit_field/extract_bit_field when trying
  1748.      to access a non-existent part of the register.  */
  1749.       if (TREE_CODE (idx) == INTEGER_CST
  1750.       && TYPE_VALUES (TREE_TYPE (array))
  1751.       && ! int_fits_type_p (idx, TYPE_VALUES (TREE_TYPE (array))))
  1752.     {
  1753.       if (mark_addressable (array) == 0)
  1754.         return error_mark_node;
  1755.     }
  1756.  
  1757.       /* Note in C++ we don't bother warning about subscripting a
  1758.      `register' array, since it's legal in C++ to take the address
  1759.      of something with that storage specification.  */
  1760.       if (pedantic && !lvalue_p (array))
  1761.     pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
  1762.  
  1763.       if (pedantic)
  1764.     {
  1765.       tree foo = array;
  1766.       while (TREE_CODE (foo) == COMPONENT_REF)
  1767.         foo = TREE_OPERAND (foo, 0);
  1768.       if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
  1769.         pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
  1770.     }
  1771.  
  1772.       type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
  1773.       rval = build (ARRAY_REF, type, array, idx);
  1774.       /* Array ref is const/volatile if the array elements are
  1775.      or if the array is..  */
  1776.       TREE_READONLY (rval)
  1777.     |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
  1778.         | TREE_READONLY (array));
  1779.       TREE_SIDE_EFFECTS (rval)
  1780.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  1781.         | TREE_SIDE_EFFECTS (array));
  1782.       TREE_THIS_VOLATILE (rval)
  1783.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  1784.         /* This was added by rms on 16 Nov 91.
  1785.            It fixes  vol struct foo *a;  a->elts[1] 
  1786.            in an inline function.
  1787.            Hope it doesn't break something else.  */
  1788.         | TREE_THIS_VOLATILE (array));
  1789.       return require_complete_type (fold (rval));
  1790.     }
  1791.  
  1792.   {
  1793.     tree ar = default_conversion (array);
  1794.     tree ind = default_conversion (idx);
  1795.  
  1796.     /* Put the integer in IND to simplify error checking.  */
  1797.     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
  1798.       {
  1799.     tree temp = ar;
  1800.     ar = ind;
  1801.     ind = temp;
  1802.       }
  1803.  
  1804.     if (ar == error_mark_node)
  1805.       return ar;
  1806.  
  1807.     if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
  1808.       {
  1809.     error ("subscripted value is neither array nor pointer");
  1810.     return error_mark_node;
  1811.       }
  1812.     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
  1813.       {
  1814.     error ("array subscript is not an integer");
  1815.     return error_mark_node;
  1816.       }
  1817.  
  1818.     return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR, ar, ind, PLUS_EXPR),
  1819.                    "array indexing");
  1820.   }
  1821. }
  1822.  
  1823. /* Build a function call to function FUNCTION with parameters PARAMS.
  1824.    PARAMS is a list--a chain of TREE_LIST nodes--in which the
  1825.    TREE_VALUE of each node is a parameter-expression.
  1826.    FUNCTION's data type may be a function type or a pointer-to-function.
  1827.  
  1828.    For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
  1829.    is the list of possible methods that FUNCTION could conceivably
  1830.    be.  If the list of methods comes from a class, then it will be
  1831.    a list of lists (where each element is associated with the class
  1832.    that produced it), otherwise it will be a simple list (for
  1833.    functions overloaded in global scope).
  1834.  
  1835.    In the first case, TREE_VALUE (function) is the head of one of those
  1836.    lists, and TREE_PURPOSE is the name of the function.
  1837.  
  1838.    In the second case, TREE_PURPOSE (function) is the function's
  1839.    name directly.
  1840.  
  1841.    DECL is the class instance variable, usually CURRENT_CLASS_DECL.  */
  1842.  
  1843. /*
  1844.  * [eichin:19911015.1726EST] actually return a possibly incomplete
  1845.  * type
  1846.  */
  1847. tree
  1848. build_x_function_call (function, params, decl)
  1849.      tree function, params, decl;
  1850. {
  1851.   tree type;
  1852.   int is_method;
  1853.  
  1854.   if (function == error_mark_node)
  1855.     return error_mark_node;
  1856.  
  1857.   type = TREE_TYPE (function);
  1858.   is_method = ((TREE_CODE (function) == TREE_LIST
  1859.         && current_class_type != NULL_TREE
  1860.         && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function)) == function)
  1861.            || TREE_CODE (function) == IDENTIFIER_NODE
  1862.            || TREE_CODE (type) == METHOD_TYPE
  1863.            || TYPE_PTRMEMFUNC_P (type));
  1864.  
  1865.   /* Handle methods, friends, and overloaded functions, respectively.  */
  1866.   if (is_method)
  1867.     {
  1868.       if (TREE_CODE (function) == FUNCTION_DECL)
  1869.     {
  1870.       if (DECL_NAME (function))
  1871.         function = DECL_NAME (function);
  1872.       else
  1873.         function = TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function));
  1874.     }
  1875.       else if (TREE_CODE (function) == TREE_LIST)
  1876.     {
  1877. #if 0
  1878.       if (TREE_CODE (TREE_VALUE (function)) == TREE_LIST)
  1879.         function = TREE_PURPOSE (TREE_VALUE (function));
  1880.       else
  1881.         function = TREE_PURPOSE (function);
  1882. #else
  1883.       my_friendly_assert (TREE_CODE (TREE_VALUE (function)) == FUNCTION_DECL, 312);
  1884.       function = TREE_PURPOSE (function);
  1885. #endif
  1886.     }
  1887.       else if (TREE_CODE (function) != IDENTIFIER_NODE)
  1888.     {
  1889.       if (TREE_CODE (function) == OFFSET_REF)
  1890.         {
  1891.           if (TREE_OPERAND (function, 0))
  1892.         decl = TREE_OPERAND (function, 0);
  1893.         }
  1894.       /* Call via a pointer to member function.  */
  1895.       if (decl == NULL_TREE)
  1896.         {
  1897.           error ("pointer to member function called, but not in class scope");
  1898.           return error_mark_node;
  1899.         }
  1900.       /* What other type of POINTER_TYPE could this be? */
  1901.       if (TREE_CODE (TREE_TYPE (function)) != POINTER_TYPE
  1902.           && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function))
  1903.           && TREE_CODE (function) != OFFSET_REF)
  1904.         function = build (OFFSET_REF, TREE_TYPE (type), NULL_TREE, function);
  1905.       goto do_x_function;
  1906.     }
  1907.  
  1908.       /* this is an abbreviated method call.
  1909.          must go through here in case it is a virtual function.
  1910.      @@ Perhaps this could be optimized.  */
  1911.  
  1912.       if (decl == NULL_TREE)
  1913.     {
  1914.       if (current_class_type == NULL_TREE)
  1915.         {
  1916.           error ("object missing in call to method `%s'",
  1917.              IDENTIFIER_POINTER (function));
  1918.           return error_mark_node;
  1919.         }
  1920.       /* Yow: call from a static member function.  */
  1921.       decl = build1 (NOP_EXPR,
  1922.              TYPE_POINTER_TO (current_class_type),
  1923.              error_mark_node);
  1924.     }
  1925.  
  1926.       return build_method_call (decl, function, params,
  1927.                 NULL_TREE, LOOKUP_NORMAL);
  1928.     }
  1929.   else if (TREE_CODE (function) == COMPONENT_REF
  1930.        && type == unknown_type_node)
  1931.     {
  1932.       /* Should we undo what was done in build_component_ref? */
  1933.       if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function, 1))) == TREE_VEC)
  1934.     /* Get the name that build_component_ref hid. */
  1935.     function = DECL_NAME (TREE_VALUE (TREE_OPERAND (function, 1)));
  1936.       else
  1937.     function = TREE_PURPOSE (TREE_OPERAND (function, 1));
  1938.       return build_method_call (decl, function, params,
  1939.                 NULL_TREE, LOOKUP_NORMAL);
  1940.     }
  1941.   else if (TREE_CODE (function) == TREE_LIST)
  1942.     {
  1943.       if (TREE_CHAIN (function) != NULL_TREE)
  1944.         {
  1945.           if (TREE_CODE (TREE_VALUE (function)) == TEMPLATE_DECL)
  1946.             return build_overload_call_maybe (TREE_PURPOSE (function),
  1947.                           params, 1, (struct candidate *)0);
  1948.           else
  1949.             return build_overload_call (TREE_PURPOSE (function), params, 1,
  1950.                     (struct candidate *)0);
  1951.         }
  1952.       else if (TREE_VALUE (function) == NULL_TREE)
  1953.     {
  1954.       error ("function `%s' declared overloaded, but no definitions appear with which to resolve it",
  1955.          IDENTIFIER_POINTER (TREE_PURPOSE (function)));
  1956.       return error_mark_node;
  1957.     }
  1958.       else if (TREE_CODE (TREE_VALUE (function)) == TEMPLATE_DECL)
  1959.     return build_overload_call_maybe (TREE_PURPOSE (function),
  1960.                       params, 1, (struct candidate *)0);
  1961.       else
  1962.     function = TREE_VALUE (function);
  1963.     }
  1964.  
  1965.  do_x_function:
  1966.   if (TREE_CODE (function) == OFFSET_REF)
  1967.     {
  1968.       /* If the component is a data element (or a virtual function), we play
  1969.      games here to make things work.  */
  1970.       tree decl_addr;
  1971.  
  1972.       if (TREE_OPERAND (function, 0))
  1973.     decl = TREE_OPERAND (function, 0);
  1974.       else
  1975.     decl = C_C_D;
  1976.  
  1977.       decl_addr = build_unary_op (ADDR_EXPR, decl, 0);
  1978.       function = get_member_function_from_ptrfunc (&decl_addr, decl,
  1979.                            TREE_OPERAND (function, 1));
  1980.       params = tree_cons (NULL_TREE, decl_addr, params);
  1981.       return build_function_call (function, params);
  1982.     }
  1983.  
  1984.   type = TREE_TYPE (function);
  1985.   if (type != error_mark_node)
  1986.     {
  1987.       if (TREE_CODE (type) == REFERENCE_TYPE)
  1988.     type = TREE_TYPE (type);
  1989.  
  1990.       if (TYPE_LANG_SPECIFIC (type) && TYPE_OVERLOADS_CALL_EXPR (type))
  1991.     return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, function, params, NULL_TREE);
  1992.     }
  1993.  
  1994.   if (is_method)
  1995.     {
  1996.       tree fntype = TREE_TYPE (function);
  1997.       tree ctypeptr;
  1998.  
  1999.       /* Explicitly named method?  */
  2000.       if (TREE_CODE (function) == FUNCTION_DECL)
  2001.     ctypeptr = TYPE_POINTER_TO (DECL_CLASS_CONTEXT (function));
  2002.       /* Expression with ptr-to-method type?  It could either be a plain
  2003.      usage, or it might be a case where the ptr-to-method is being
  2004.      passed in as an argument.  */
  2005.       else if (TYPE_PTRMEMFUNC_P (fntype))
  2006.     {
  2007.       tree rec = TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype)));
  2008.       ctypeptr = TYPE_POINTER_TO (rec);
  2009.     }
  2010.       /* Unexpected node type?  */
  2011.       else
  2012.     my_friendly_abort (116);
  2013.       if (decl == NULL_TREE)
  2014.     {
  2015.       if (current_function_decl
  2016.           && DECL_STATIC_FUNCTION_P (current_function_decl))
  2017.         error ("invalid call to member function needing `this' in static member function scope");
  2018.       else
  2019.         error ("pointer to member function called, but not in class scope");
  2020.       return error_mark_node;
  2021.     }
  2022.       if (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE
  2023.       && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))
  2024.     {
  2025.       decl = build_unary_op (ADDR_EXPR, decl, 0);
  2026.       decl = convert_pointer_to (TREE_TYPE (ctypeptr), decl);
  2027.     }
  2028.       else
  2029.     decl = build_c_cast (ctypeptr, decl);
  2030.       params = tree_cons (NULL_TREE, decl, params);
  2031.     }
  2032.  
  2033.   return build_function_call (function, params);
  2034. }
  2035.  
  2036. /* Resolve a pointer to member function.  INSTANCE is the object
  2037.    instance to use, if the member points to a virtual member.  */
  2038.  
  2039. tree
  2040. get_member_function_from_ptrfunc (instance_ptrptr, instance, function)
  2041.      tree *instance_ptrptr;
  2042.      tree instance;
  2043.      tree function;
  2044. {
  2045.   if (TREE_CODE (function) == OFFSET_REF)
  2046.     {
  2047.       function = TREE_OPERAND (function, 1);
  2048.     }
  2049.  
  2050.   if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
  2051.     {
  2052.       tree fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
  2053.       tree index = save_expr (convert (integer_type_node,
  2054.                        build_component_ref (function,
  2055.                                 index_identifier,
  2056.                                 0, 0)));
  2057.       tree e1 = build (GT_EXPR, integer_type_node, index, integer_zero_node);
  2058.       tree delta = build_component_ref (function, delta_identifier, 0, 0);
  2059.       tree delta2 = DELTA2_FROM_PTRMEMFUNC (function);
  2060.       tree e2;
  2061.       tree e3;
  2062.       tree aref, vtbl;
  2063.  
  2064.       vtbl = build1 (ADDR_EXPR, ptr_type_node, instance);
  2065.       vtbl = build (PLUS_EXPR,
  2066.             build_pointer_type (build_pointer_type (vtable_entry_type)),
  2067.             vtbl, convert (sizetype, delta2));
  2068.       vtbl = build_indirect_ref (vtbl, NULL_PTR);
  2069.       aref = build_array_ref (vtbl, size_binop (MINUS_EXPR,
  2070.                         index,
  2071.                         integer_one_node));
  2072.       aref = save_expr (aref);
  2073.  
  2074.       /* Save the intermediate result in a SAVE_EXPR so we don't have to
  2075.      compute each component of the virtual function pointer twice.  */ 
  2076.      if (/* !building_cleanup && */ TREE_CODE (aref) == INDIRECT_REF)
  2077.     TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
  2078.       
  2079.       delta = build (PLUS_EXPR, integer_type_node,
  2080.              build_conditional_expr (e1, build_component_ref (aref, delta_identifier, 0, 0), integer_zero_node),
  2081.              delta);
  2082.  
  2083.       *instance_ptrptr = build (PLUS_EXPR, TREE_TYPE (*instance_ptrptr),
  2084.                 *instance_ptrptr,
  2085.                 convert (integer_type_node, delta));
  2086.       e2 = build_component_ref (aref, pfn_identifier, 0, 0);
  2087.  
  2088.       e3 = PFN_FROM_PTRMEMFUNC (function);
  2089.       TREE_TYPE (e2) = TREE_TYPE (e3);
  2090.       function = build_conditional_expr (e1, e2, e3);
  2091.     }
  2092.   return function;
  2093. }
  2094.  
  2095. tree
  2096. build_function_call_real (function, params, require_complete)
  2097.      tree function, params;
  2098.      int require_complete;
  2099. {
  2100.   register tree fntype, fndecl;
  2101.   register tree value_type;
  2102.   register tree coerced_params;
  2103.   int is_method;
  2104.  
  2105.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  2106.      Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context.  */
  2107.   if (TREE_CODE (function) == NOP_EXPR
  2108.       && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0)))
  2109.     function = TREE_OPERAND (function, 0);
  2110.  
  2111.   if (TREE_CODE (function) == FUNCTION_DECL)
  2112.     {
  2113.       GNU_xref_call (current_function_decl,
  2114.              IDENTIFIER_POINTER (DECL_NAME (function)
  2115.                      ? DECL_NAME (function)
  2116.                      : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function))));
  2117.       assemble_external (function);
  2118.       fndecl = function;
  2119.  
  2120.       /* Convert anything with function type to a pointer-to-function.  */
  2121.       if (pedantic
  2122.       && DECL_NAME (function)
  2123.       && IDENTIFIER_LENGTH (DECL_NAME (function)) == 4
  2124.       && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (function)), "main")
  2125.       && DECL_CONTEXT (function) == NULL_TREE)
  2126.     {
  2127.       pedwarn ("ANSI C++ forbids calling `main' from within program");
  2128.     }
  2129.  
  2130.       /* Differs from default_conversion by not setting TREE_ADDRESSABLE
  2131.      (because calling an inline function does not mean the function
  2132.      needs to be separately compiled).  */
  2133.  
  2134.       if (! DECL_INLINE (function))
  2135.     {
  2136.       assemble_external (function);
  2137.       TREE_USED (function) = 1;
  2138.     }
  2139.  
  2140.       fntype = build_type_variant (TREE_TYPE (function),
  2141.                    TREE_READONLY (function),
  2142.                    TREE_THIS_VOLATILE (function));
  2143.       function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
  2144.     }
  2145.   else
  2146.     {
  2147.       fndecl = NULL_TREE;
  2148.  
  2149.       /* Convert anything with function type to a pointer-to-function.  */
  2150.       if (function == error_mark_node)
  2151.     return error_mark_node;
  2152.       function = default_conversion (function);
  2153.     }
  2154.  
  2155.   fntype = TREE_TYPE (function);
  2156.  
  2157.   if (TYPE_PTRMEMFUNC_P (fntype))
  2158.     {
  2159.       tree instance_ptr = build_unary_op (ADDR_EXPR, C_C_D, 0);
  2160.       fntype = TYPE_PTRMEMFUNC_FN_TYPE (fntype);
  2161.       function = get_member_function_from_ptrfunc (&instance_ptr, C_C_D, function);
  2162.     }
  2163.  
  2164.   is_method = (TREE_CODE (fntype) == POINTER_TYPE
  2165.            && TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE);
  2166.  
  2167.   if (!((TREE_CODE (fntype) == POINTER_TYPE
  2168.      && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)
  2169.     || is_method))
  2170.     {
  2171.       error ("called object is not a function");
  2172.       return error_mark_node;
  2173.     }
  2174.  
  2175.   /* fntype now gets the type of function pointed to.  */
  2176.   fntype = TREE_TYPE (fntype);
  2177.  
  2178.   /* Convert the parameters to the types declared in the
  2179.      function prototype, or apply default promotions.  */
  2180.  
  2181.   coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
  2182.                       params, fndecl, LOOKUP_NORMAL);
  2183.  
  2184.   /* Recognize certain built-in functions so we can make tree-codes
  2185.      other than CALL_EXPR.  We do this when it enables fold-const.c
  2186.      to do something useful.  */
  2187.  
  2188.   if (TREE_CODE (function) == ADDR_EXPR
  2189.       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
  2190.       && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
  2191.     switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
  2192.       {
  2193.       case BUILT_IN_ABS:
  2194.       case BUILT_IN_LABS:
  2195.       case BUILT_IN_FABS:
  2196.     if (coerced_params == 0)
  2197.       return integer_zero_node;
  2198.     return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
  2199.       }
  2200.  
  2201.   /* C++ */
  2202.   value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
  2203.   {
  2204.     register tree result = 
  2205.       build (CALL_EXPR, value_type,
  2206.          function, coerced_params, NULL_TREE);
  2207.  
  2208.     TREE_SIDE_EFFECTS (result) = 1;
  2209.     TREE_RAISES (result) |= !! TYPE_RAISES_EXCEPTIONS (fntype);
  2210.     if (! require_complete)
  2211.       return result;
  2212.     if (value_type == void_type_node)
  2213.       return result;
  2214.     return require_complete_type (result);
  2215.   }
  2216. }
  2217.  
  2218. tree
  2219. build_function_call (function, params)
  2220.      tree function, params;
  2221. {
  2222.   return build_function_call_real (function, params, 1);
  2223. }
  2224.      
  2225. tree
  2226. build_function_call_maybe (function, params)
  2227.      tree function, params;
  2228. {
  2229.   return build_function_call_real (function, params, 0);
  2230. }
  2231.  
  2232.  
  2233. /* Convert the actual parameter expressions in the list VALUES
  2234.    to the types in the list TYPELIST.
  2235.    If parmdecls is exhausted, or when an element has NULL as its type,
  2236.    perform the default conversions.
  2237.  
  2238.    RETURN_LOC is the location of the return value, if known, NULL_TREE
  2239.    otherwise.  This is useful in the case where we can avoid creating
  2240.    a temporary variable in the case where we can initialize the return
  2241.    value directly.  If we are not eliding constructors, then we set this
  2242.    to NULL_TREE to avoid this avoidance.
  2243.  
  2244.    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
  2245.  
  2246.    This is also where warnings about wrong number of args are generated.
  2247.    
  2248.    Return a list of expressions for the parameters as converted.
  2249.  
  2250.    Both VALUES and the returned value are chains of TREE_LIST nodes
  2251.    with the elements of the list in the TREE_VALUE slots of those nodes.
  2252.  
  2253.    In C++, unspecified trailing parameters can be filled in with their
  2254.    default arguments, if such were specified.  Do so here.  */
  2255.  
  2256. tree
  2257. convert_arguments (return_loc, typelist, values, fndecl, flags)
  2258.      tree return_loc, typelist, values, fndecl;
  2259.      int flags;
  2260. {
  2261.   extern tree gc_protect_fndecl;
  2262.   register tree typetail, valtail;
  2263.   register tree result = NULL_TREE;
  2264.   char *called_thing;
  2265.   int maybe_raises = 0;
  2266.   int i = 0;
  2267.  
  2268.   if (! flag_elide_constructors)
  2269.     return_loc = 0;
  2270.  
  2271.   if (fndecl)
  2272.     {
  2273.       if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
  2274.     {
  2275.       if (DECL_NAME (fndecl) == NULL_TREE
  2276.           || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl)))
  2277.         called_thing = "constructor";
  2278.       else
  2279.         called_thing = "member function";
  2280.       i -= 1;
  2281.     }
  2282.       else
  2283.     {
  2284.       called_thing = "function";
  2285.     }
  2286.     }
  2287.  
  2288.   for (valtail = values, typetail = typelist;
  2289.        valtail;
  2290.        valtail = TREE_CHAIN (valtail), i++)
  2291.     {
  2292.       register tree type = typetail ? TREE_VALUE (typetail) : 0;
  2293.       register tree val = TREE_VALUE (valtail);
  2294.  
  2295.       if (type == void_type_node)
  2296.     {
  2297.       if (fndecl)
  2298.         {
  2299.           char *buf = (char *)alloca (40 + strlen (called_thing));
  2300.           sprintf (buf, "too many arguments to %s `%%s'", called_thing);
  2301.           error_with_decl (fndecl, buf);
  2302.           error ("at this point in file");
  2303.         }
  2304.       else
  2305.         error ("too many arguments to function");
  2306.       /* In case anybody wants to know if this argument
  2307.          list is valid.  */
  2308.       if (result)
  2309.         TREE_TYPE (tree_last (result)) = error_mark_node;
  2310.       break;
  2311.     }
  2312.  
  2313.       /* The tree type of the parameter being passed may not yet be
  2314.      known.  In this case, its type is TYPE_UNKNOWN, and will
  2315.      be instantiated by the type given by TYPE.  If TYPE
  2316.      is also NULL, the tree type of VAL is ERROR_MARK_NODE.  */
  2317.       if (type && type_unknown_p (val))
  2318.     val = require_instantiated_type (type, val, integer_zero_node);
  2319.       else if (type_unknown_p (val))
  2320.     {
  2321.       /* Strip the `&' from an overloaded FUNCTION_DECL.  */
  2322.       if (TREE_CODE (val) == ADDR_EXPR)
  2323.         val = TREE_OPERAND (val, 0);
  2324.       if (TREE_CODE (val) == TREE_LIST
  2325.           && TREE_CHAIN (val) == NULL_TREE
  2326.           && TREE_TYPE (TREE_VALUE (val)) != NULL_TREE
  2327.           && (TREE_TYPE (val) == unknown_type_node
  2328.           || DECL_CHAIN (TREE_VALUE (val)) == NULL_TREE))
  2329.         /* Instantiates automatically.  */
  2330.         val = TREE_VALUE (val);
  2331.       else
  2332.         {
  2333.           error ("insufficient type information in parameter list");
  2334.           val = integer_zero_node;
  2335.         }
  2336.     }
  2337.       else if (TREE_CODE (val) == OFFSET_REF)
  2338.     val = resolve_offset_ref (val);
  2339.  
  2340.       {
  2341. #if 0
  2342.     /* This code forces the assumption that if we have a ptr-to-func
  2343.        type in an arglist, that every routine that wants to check
  2344.        its validity has done so, and thus we need not do any
  2345.        more conversion.  I don't remember why this is necessary.  */
  2346.     else if (TREE_CODE (ttype) == FUNCTION_TYPE
  2347.          && (type == NULL
  2348.              || TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
  2349.              || TREE_CODE (TREE_TYPE (type)) == VOID_TYPE))
  2350.       {
  2351.         type = build_pointer_type (ttype);
  2352.       }
  2353. #endif
  2354.       }
  2355.  
  2356.       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  2357.      Strip such NOP_EXPRs, since VAL is used in non-lvalue context.  */
  2358.       if (TREE_CODE (val) == NOP_EXPR
  2359.       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
  2360.     val = TREE_OPERAND (val, 0);
  2361.  
  2362.       if ((type == 0 || TREE_CODE (type) != REFERENCE_TYPE)
  2363.       && (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
  2364.           || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE
  2365.           || TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE))
  2366.     val = default_conversion (val);
  2367.  
  2368.       val = require_complete_type (val);
  2369.  
  2370.       if (val == error_mark_node)
  2371.     continue;
  2372.  
  2373.       maybe_raises |= TREE_RAISES (val);
  2374.  
  2375.       if (type != 0)
  2376.     {
  2377.       /* Formal parm type is specified by a function prototype.  */
  2378.       tree parmval;
  2379.  
  2380.       if (TYPE_SIZE (type) == 0)
  2381.         {
  2382.           error ("parameter type of called function is incomplete");
  2383.           parmval = val;
  2384.         }
  2385.       else
  2386.         {
  2387. #ifdef PROMOTE_PROTOTYPES
  2388.           /* Rather than truncating and then reextending,
  2389.          convert directly to int, if that's the type we will want.  */
  2390.           if (! flag_traditional
  2391.           && (TREE_CODE (type) == INTEGER_TYPE
  2392.               || TREE_CODE (type) == ENUMERAL_TYPE)
  2393.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  2394.         type = integer_type_node;
  2395. #endif
  2396.           parmval = convert_for_initialization (return_loc, type, val, flags,
  2397.                             "argument passing", fndecl, i);
  2398. #ifdef PROMOTE_PROTOTYPES
  2399.           if ((TREE_CODE (type) == INTEGER_TYPE
  2400.            || TREE_CODE (type) == ENUMERAL_TYPE)
  2401.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  2402.         parmval = default_conversion (parmval);
  2403. #endif
  2404.         }
  2405.       result = tree_cons (NULL_TREE, parmval, result);
  2406.     }
  2407.       else
  2408.     {
  2409.       if (TREE_CODE (TREE_TYPE (val)) == REFERENCE_TYPE)
  2410.         val = convert_from_reference (val);
  2411.  
  2412.       if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
  2413.           && (TYPE_PRECISION (TREE_TYPE (val))
  2414.           < TYPE_PRECISION (double_type_node)))
  2415.         /* Convert `float' to `double'.  */
  2416.         result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
  2417.       else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val))
  2418.            && (TYPE_GETS_INIT_REF (TREE_TYPE (val))
  2419.                || TYPE_GETS_ASSIGN_REF (TREE_TYPE (val))))
  2420.         {
  2421.           warning ("cannot pass objects of type `%s' through `...'",
  2422.                TYPE_NAME_STRING (TREE_TYPE (val)));
  2423.           result = tree_cons (NULL_TREE, val, result);
  2424.         }
  2425.       else
  2426.         /* Convert `short' and `char' to full-size `int'.  */
  2427.         result = tree_cons (NULL_TREE, default_conversion (val), result);
  2428.     }
  2429.  
  2430.       if (flag_gc
  2431.       /* There are certain functions for which we don't need
  2432.          to protect our arguments.  GC_PROTECT_FNDECL is one.  */
  2433.       && fndecl != gc_protect_fndecl
  2434.       && type_needs_gc_entry (TREE_TYPE (TREE_VALUE (result)))
  2435.       && ! value_safe_from_gc (NULL_TREE, TREE_VALUE (result)))
  2436.     /* This will build a temporary variable whose cleanup is
  2437.        to clear the obstack entry.  */
  2438.     TREE_VALUE (result) = protect_value_from_gc (NULL_TREE,
  2439.                              TREE_VALUE (result));
  2440.  
  2441.       if (typetail)
  2442.     typetail = TREE_CHAIN (typetail);
  2443.     }
  2444.  
  2445.   if (typetail != 0 && typetail != void_list_node)
  2446.     {
  2447.       /* See if there are default arguments that can be used */
  2448.       if (TREE_PURPOSE (typetail))
  2449.     {
  2450.       while (typetail != void_list_node)
  2451.         {
  2452.           tree type = TREE_VALUE (typetail);
  2453.           tree val = TREE_PURPOSE (typetail);
  2454.           tree parmval;
  2455.  
  2456.           if (val == NULL_TREE)
  2457.         parmval = error_mark_node;
  2458.           else if (TREE_CODE (val) == CONSTRUCTOR)
  2459.         {
  2460.           parmval = digest_init (type, val, (tree *)0);
  2461.           parmval = convert_for_initialization (return_loc, type, parmval, flags,
  2462.                             "default constructor", fndecl, i);
  2463.         }
  2464.           else
  2465.         {
  2466.           /* This could get clobbered by the following call.  */
  2467.           if (TREE_HAS_CONSTRUCTOR (val))
  2468.             val = copy_node (val);
  2469.  
  2470.           parmval = convert_for_initialization (return_loc, type, val, flags,
  2471.                             "default argument", fndecl, i);
  2472. #ifdef PROMOTE_PROTOTYPES
  2473.           if ((TREE_CODE (type) == INTEGER_TYPE
  2474.                || TREE_CODE (type) == ENUMERAL_TYPE)
  2475.               && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  2476.             parmval = default_conversion (parmval);
  2477. #endif
  2478.         }
  2479.           maybe_raises |= TREE_RAISES (parmval);
  2480.  
  2481.           if (flag_gc
  2482.           && type_needs_gc_entry (TREE_TYPE (parmval))
  2483.           && ! value_safe_from_gc (NULL_TREE, parmval))
  2484.         parmval = protect_value_from_gc (NULL_TREE, parmval);
  2485.  
  2486.           result = tree_cons (0, parmval, result);
  2487.           typetail = TREE_CHAIN (typetail);
  2488.           /* ends with `...'.  */
  2489.           if (typetail == NULL_TREE)
  2490.         break;
  2491.         }
  2492.     }
  2493.       else
  2494.     {
  2495.       if (fndecl)
  2496.         {
  2497.           char *buf = (char *)alloca (32 + strlen (called_thing));
  2498.           sprintf (buf, "too few arguments to %s `%%#D'", called_thing);
  2499.           cp_error_at (buf, fndecl);
  2500.           error ("at this point in file");
  2501.         }
  2502.       else
  2503.         error ("too few arguments to function");
  2504.       return error_mark_list;
  2505.     }
  2506.     }
  2507.   if (result)
  2508.     TREE_RAISES (result) = maybe_raises;
  2509.  
  2510.   return nreverse (result);
  2511. }
  2512.  
  2513. /* Build a binary-operation expression, after performing default
  2514.    conversions on the operands.  CODE is the kind of expression to build.  */
  2515.  
  2516. tree
  2517. build_x_binary_op (code, arg1, arg2)
  2518.      enum tree_code code;
  2519.      tree arg1, arg2;
  2520. {
  2521.   tree rval;
  2522.  
  2523.   /* If there's any way we can call this function, do so.  */
  2524.   if (rval = build_opfncall (code, 0, arg1, arg2, NULL_TREE))
  2525.     {
  2526.       /* If it's accessible, we win.  */
  2527.       if (rval = build_opfncall (code, LOOKUP_PROTECT, arg1, arg2, NULL_TREE))
  2528.     return rval;
  2529.       /* Else, report an error.  */
  2530.       build_opfncall (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE);
  2531.       return error_mark_node;
  2532.     }
  2533.   if (code == MEMBER_REF)
  2534.     return build_m_component_ref (build_indirect_ref (arg1, NULL_PTR),
  2535.                   arg2);
  2536.   return build_binary_op (code, arg1, arg2, 1);
  2537. }
  2538.  
  2539. tree
  2540. build_binary_op (code, arg1, arg2, convert_p)
  2541.      enum tree_code code;
  2542.      tree arg1, arg2;
  2543.      int convert_p;
  2544. {
  2545.   tree type1, type2;
  2546.   tree args[2];
  2547.  
  2548.   args[0] = arg1;
  2549.   args[1] = arg2;
  2550.  
  2551.   if (convert_p)
  2552.     {
  2553.       args[0] = default_conversion (args[0]);
  2554.       args[1] = default_conversion (args[1]);
  2555.  
  2556.       if (type_unknown_p (args[0]))
  2557.     {
  2558.       args[0] = instantiate_type (TREE_TYPE (args[1]), args[0], 1);
  2559.       args[0] = default_conversion (args[0]);
  2560.     }
  2561.       else if (type_unknown_p (args[1]))
  2562.     {
  2563.       args[1] = require_instantiated_type (TREE_TYPE (args[0]),
  2564.                            args[1],
  2565.                            error_mark_node);
  2566.       args[1] = default_conversion (args[1]);
  2567.     }
  2568.  
  2569.       type1 = TREE_TYPE (args[0]);
  2570.       type2 = TREE_TYPE (args[1]);
  2571.  
  2572.       if (IS_AGGR_TYPE_2 (type1, type2) && ! TYPE_PTRMEMFUNC_P (type1))
  2573.     {
  2574.       /* Try to convert this to something reasonable.  */
  2575.       if (! build_default_binary_type_conversion(code, &args[0], &args[1]))
  2576.         return error_mark_node;
  2577.     }
  2578.       else if ((IS_AGGR_TYPE (type1) && ! TYPE_PTRMEMFUNC_P (type1))
  2579.            || (IS_AGGR_TYPE (type2) && ! TYPE_PTRMEMFUNC_P (type2)))
  2580.     {
  2581.       int convert_index = IS_AGGR_TYPE (type2);
  2582.       /* Avoid being tripped up by things like (ARG1 != 0).  */
  2583.       tree types[2], try;
  2584.       
  2585.       types[0] = type1; types[1] = type2;
  2586.       try = build_type_conversion (code, types[convert_index ^ 1],
  2587.                        args[convert_index], 1);
  2588.       
  2589.       if (try == 0
  2590.           && args[1] == integer_zero_node
  2591.           && (code == NE_EXPR || code == EQ_EXPR))
  2592.         try = build_type_conversion (code, ptr_type_node,
  2593.                      args[convert_index], 1);
  2594.       if (try == 0)
  2595.         {
  2596.           cp_error ("no member function `%T::operator %s(%#T)'",
  2597.               types[convert_index],
  2598.               opname_tab[(int) code]
  2599.               ? opname_tab[(int) code] : "<unknown>",
  2600.               types[convert_index ^ 1]);
  2601.           return error_mark_node;
  2602.         }
  2603.       if (try == error_mark_node)
  2604.         error ("ambiguous pointer conversion");
  2605.       args[convert_index] = try;
  2606.     }
  2607.     }
  2608.   return build_binary_op_nodefault (code, args[0], args[1], code);
  2609. }
  2610.  
  2611. /* Build a binary-operation expression without default conversions.
  2612.    CODE is the kind of expression to build.
  2613.    This function differs from `build' in several ways:
  2614.    the data type of the result is computed and recorded in it,
  2615.    warnings are generated if arg data types are invalid,
  2616.    special handling for addition and subtraction of pointers is known,
  2617.    and some optimization is done (operations on narrow ints
  2618.    are done in the narrower type when that gives the same result).
  2619.    Constant folding is also done before the result is returned.
  2620.  
  2621.    ERROR_CODE is the code that determines what to say in error messages.
  2622.    It is usually, but not always, the same as CODE.
  2623.  
  2624.    Note that the operands will never have enumeral types
  2625.    because either they have just had the default conversions performed
  2626.    or they have both just been converted to some other type in which
  2627.    the arithmetic is to be done.
  2628.  
  2629.    C++: must do special pointer arithmetic when implementing
  2630.    multiple inheritance, and deal with pointer to member functions.  */
  2631.  
  2632. tree
  2633. build_binary_op_nodefault (code, op0, op1, error_code)
  2634.      enum tree_code code;
  2635.      tree op0, op1;
  2636.      enum tree_code error_code;
  2637. {
  2638.   tree type0 = TREE_TYPE (op0), type1 = TREE_TYPE (op1);
  2639.  
  2640.   /* The expression codes of the data types of the arguments tell us
  2641.      whether the arguments are integers, floating, pointers, etc.  */
  2642.   register enum tree_code code0 = TREE_CODE (type0);
  2643.   register enum tree_code code1 = TREE_CODE (type1);
  2644.  
  2645.   /* Expression code to give to the expression when it is built.
  2646.      Normally this is CODE, which is what the caller asked for,
  2647.      but in some special cases we change it.  */
  2648.   register enum tree_code resultcode = code;
  2649.  
  2650.   /* Data type in which the computation is to be performed.
  2651.      In the simplest cases this is the common type of the arguments.  */
  2652.   register tree result_type = NULL;
  2653.  
  2654.   /* Nonzero means operands have already been type-converted
  2655.      in whatever way is necessary.
  2656.      Zero means they need to be converted to RESULT_TYPE.  */
  2657.   int converted = 0;
  2658.  
  2659.   /* Nonzero means after finally constructing the expression
  2660.      give it this type.  Otherwise, give it type RESULT_TYPE.  */
  2661.   tree final_type = 0;
  2662.  
  2663.   /* Nonzero if this is an operation like MIN or MAX which can
  2664.      safely be computed in short if both args are promoted shorts.
  2665.      Also implies COMMON.
  2666.      -1 indicates a bitwise operation; this makes a difference
  2667.      in the exact conditions for when it is safe to do the operation
  2668.      in a narrower mode.  */
  2669.   int shorten = 0;
  2670.  
  2671.   /* Nonzero if this is a comparison operation;
  2672.      if both args are promoted shorts, compare the original shorts.
  2673.      Also implies COMMON.  */
  2674.   int short_compare = 0;
  2675.  
  2676.   /* Nonzero if this is a right-shift operation, which can be computed on the
  2677.      original short and then promoted if the operand is a promoted short.  */
  2678.   int short_shift = 0;
  2679.  
  2680.   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
  2681.   int common = 0;
  2682.  
  2683.   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
  2684.   STRIP_TYPE_NOPS (op0);
  2685.   STRIP_TYPE_NOPS (op1);
  2686.  
  2687.   /* If an error was already reported for one of the arguments,
  2688.      avoid reporting another error.  */
  2689.  
  2690.   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
  2691.     return error_mark_node;
  2692.  
  2693.   switch (code)
  2694.     {
  2695.     case PLUS_EXPR:
  2696.       /* Handle the pointer + int case.  */
  2697.       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2698.     return pointer_int_sum (PLUS_EXPR, op0, op1);
  2699.       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
  2700.     return pointer_int_sum (PLUS_EXPR, op1, op0);
  2701.       else
  2702.     common = 1;
  2703.       break;
  2704.  
  2705.     case MINUS_EXPR:
  2706.       /* Subtraction of two similar pointers.
  2707.      We must subtract them as integers, then divide by object size.  */
  2708.       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
  2709.       && comp_target_types (type0, type1, 1))
  2710.     return pointer_diff (op0, op1);
  2711.       /* Handle pointer minus int.  Just like pointer plus int.  */
  2712.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2713.     return pointer_int_sum (MINUS_EXPR, op0, op1);
  2714.       else
  2715.     common = 1;
  2716.       break;
  2717.  
  2718.     case MULT_EXPR:
  2719.       common = 1;
  2720.       break;
  2721.  
  2722.     case TRUNC_DIV_EXPR:
  2723.     case CEIL_DIV_EXPR:
  2724.     case FLOOR_DIV_EXPR:
  2725.     case ROUND_DIV_EXPR:
  2726.     case EXACT_DIV_EXPR:
  2727.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2728.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2729.     {
  2730.       if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
  2731.         resultcode = RDIV_EXPR;
  2732.       else
  2733.         shorten = 1;
  2734.       common = 1;
  2735.     }
  2736.       break;
  2737.  
  2738.     case BIT_AND_EXPR:
  2739.     case BIT_ANDTC_EXPR:
  2740.     case BIT_IOR_EXPR:
  2741.     case BIT_XOR_EXPR:
  2742.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2743.     shorten = -1;
  2744.       /* If one operand is a constant, and the other is a short type
  2745.      that has been converted to an int,
  2746.      really do the work in the short type and then convert the
  2747.      result to int.  If we are lucky, the constant will be 0 or 1
  2748.      in the short type, making the entire operation go away.  */
  2749.       if (TREE_CODE (op0) == INTEGER_CST
  2750.       && TREE_CODE (op1) == NOP_EXPR
  2751.       && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
  2752.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
  2753.     {
  2754.       final_type = result_type;
  2755.       op1 = TREE_OPERAND (op1, 0);
  2756.       result_type = TREE_TYPE (op1);
  2757.     }
  2758.       if (TREE_CODE (op1) == INTEGER_CST
  2759.       && TREE_CODE (op0) == NOP_EXPR
  2760.       && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
  2761.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  2762.     {
  2763.       final_type = result_type;
  2764.       op0 = TREE_OPERAND (op0, 0);
  2765.       result_type = TREE_TYPE (op0);
  2766.     }
  2767.       break;
  2768.  
  2769.     case TRUNC_MOD_EXPR:
  2770.     case FLOOR_MOD_EXPR:
  2771.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2772.     shorten = 1;
  2773.       break;
  2774.  
  2775.     case TRUTH_ANDIF_EXPR:
  2776.     case TRUTH_ORIF_EXPR:
  2777.     case TRUTH_AND_EXPR:
  2778.     case TRUTH_OR_EXPR:
  2779.       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE || code0 == REAL_TYPE)
  2780.       && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE || code1 == REAL_TYPE))
  2781.     {
  2782.       /* Result of these operations is always an int,
  2783.          but that does not mean the operands should be
  2784.          converted to ints!  */
  2785.       result_type = integer_type_node;
  2786.       op0 = truthvalue_conversion (op0);
  2787.       op1 = truthvalue_conversion (op1);
  2788.       converted = 1;
  2789.     }
  2790.       break;
  2791.  
  2792.       /* Shift operations: result has same type as first operand;
  2793.      always convert second operand to int.
  2794.      Also set SHORT_SHIFT if shifting rightward.  */
  2795.  
  2796.     case RSHIFT_EXPR:
  2797.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2798.     {
  2799.       result_type = type0;
  2800.       if (TREE_CODE (op1) == INTEGER_CST)
  2801.         {
  2802.           if (tree_int_cst_lt (op1, integer_zero_node))
  2803.         warning ("right shift count is negative");
  2804.           else
  2805.         {
  2806.           if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
  2807.             short_shift = 1;
  2808.           if (TREE_INT_CST_HIGH (op1) != 0
  2809.               || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2810.               >= TYPE_PRECISION (type0)))
  2811.             warning ("right shift count >= width of type");
  2812.         }
  2813.         }
  2814.       /* Convert the shift-count to an integer, regardless of
  2815.          size of value being shifted.  */
  2816.       if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2817.         op1 = convert (integer_type_node, op1);
  2818.       /* Avoid converting op1 to result_type later.  */
  2819.       converted = 1;
  2820.     }
  2821.       break;
  2822.  
  2823.     case LSHIFT_EXPR:
  2824.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2825.     {
  2826.       result_type = type0;
  2827.       if (TREE_CODE (op1) == INTEGER_CST)
  2828.         {
  2829.           if (tree_int_cst_lt (op1, integer_zero_node))
  2830.         warning ("left shift count is negative");
  2831.           else if (TREE_INT_CST_HIGH (op1) != 0
  2832.                || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2833.                >= TYPE_PRECISION (type0)))
  2834.         warning ("left shift count >= width of type");
  2835.         }
  2836.       /* Convert the shift-count to an integer, regardless of
  2837.          size of value being shifted.  */
  2838.       if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2839.         op1 = convert (integer_type_node, op1);
  2840.       /* Avoid converting op1 to result_type later.  */
  2841.       converted = 1;
  2842.     }
  2843.       break;
  2844.  
  2845.     case RROTATE_EXPR:
  2846.     case LROTATE_EXPR:
  2847.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2848.     {
  2849.       result_type = type0;
  2850.       if (TREE_CODE (op1) == INTEGER_CST)
  2851.         {
  2852.           if (tree_int_cst_lt (op1, integer_zero_node))
  2853.         warning ("%s rotate count is negative",
  2854.              (code == LROTATE_EXPR) ? "left" : "right");
  2855.           else if (TREE_INT_CST_HIGH (op1) != 0
  2856.                || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2857.                >= TYPE_PRECISION (type0)))
  2858.         warning ("%s rotate count >= width of type",
  2859.              (code == LROTATE_EXPR) ? "left" : "right");
  2860.         }
  2861.       /* Convert the shift-count to an integer, regardless of
  2862.          size of value being shifted.  */
  2863.       if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2864.         op1 = convert (integer_type_node, op1);
  2865.     }
  2866.       break;
  2867.  
  2868.     case EQ_EXPR:
  2869.     case NE_EXPR:
  2870.       /* Result of comparison is always int,
  2871.      but don't convert the args to int!  */
  2872.       result_type = integer_type_node;
  2873.       converted = 1;
  2874.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2875.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2876.     short_compare = 1;
  2877.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2878.     {
  2879.       register tree tt0 = TYPE_MAIN_VARIANT (TREE_TYPE (type0));
  2880.       register tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (type1));
  2881.       /* Anything compares with void *.  void * compares with anything.
  2882.          Otherwise, the targets must be the same.  */
  2883.       if (tt0 != tt1 && TREE_CODE (tt0) == RECORD_TYPE
  2884.           && TREE_CODE (tt1) == RECORD_TYPE)
  2885.         {
  2886.           tree base = common_base_type (tt0, tt1);
  2887.  
  2888.           if (base == NULL_TREE)
  2889. #ifdef OBJCPLUS
  2890.         {
  2891.           if (maybe_objc_comptypes (tt0, tt1, 1) != 1)
  2892.             warning ("comparison of distinct object pointer types");
  2893.         }
  2894. #else
  2895.         warning ("comparison of distinct object pointer types");
  2896. #endif
  2897.           else if (base == error_mark_node)
  2898.         {
  2899.           message_2_types (error, "comparison of pointer types `%s*' and `%s*' requires conversion to ambiguous supertype", tt0, tt1);
  2900.           return error_mark_node;
  2901.         }
  2902.           else
  2903.         {
  2904.           if (integer_zerop (op0))
  2905.             op0 = null_pointer_node;
  2906.           else
  2907.             op0 = convert_pointer_to (base, op0);
  2908.           if (integer_zerop (op1))
  2909.             op1 = null_pointer_node;
  2910.           else
  2911.             op1 = convert_pointer_to (base, op1);
  2912.         }
  2913.         }
  2914.       else if (comp_target_types (type0, type1, 1))
  2915.         ;
  2916.       else if (tt0 == void_type_node)
  2917.         {
  2918.           if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
  2919.         pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
  2920.         }
  2921.       else if (tt1 == void_type_node)
  2922.         {
  2923.           if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
  2924.         pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
  2925.         }
  2926.       else
  2927.         pedwarn ("comparison of distinct pointer types lacks a cast");
  2928.     }
  2929.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  2930.            && integer_zerop (op1))
  2931.     op1 = null_pointer_node;
  2932.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  2933.            && integer_zerop (op0))
  2934.     op0 = null_pointer_node;
  2935.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2936.     {
  2937.       error ("ANSI C++ forbids comparison between pointer and integer");
  2938.       op1 = convert (TREE_TYPE (op0), op1);
  2939.     }
  2940.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  2941.     {
  2942.       error ("ANSI C++ forbids comparison between pointer and integer");
  2943.       op0 = convert (TREE_TYPE (op1), op0);
  2944.     }
  2945.       else if (TYPE_PTRMEMFUNC_P (type0) && TREE_CODE (op1) == INTEGER_CST
  2946.            && integer_zerop (op1))
  2947.     {
  2948.       op0 = build_component_ref (op0, index_identifier, 0, 0);
  2949.       op1 = integer_zero_node;
  2950.     }
  2951.       else if (TYPE_PTRMEMFUNC_P (type1) && TREE_CODE (op0) == INTEGER_CST
  2952.            && integer_zerop (op0))
  2953.     {
  2954.       op0 = build_component_ref (op1, index_identifier, 0, 0);
  2955.       op1 = integer_zero_node;
  2956.     }
  2957.       else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1)
  2958.            && (TYPE_PTRMEMFUNC_FN_TYPE (type0)
  2959.            == TYPE_PTRMEMFUNC_FN_TYPE (type1)))
  2960.     {
  2961.       /* The code we generate for the test is:
  2962.  
  2963.       (op0.index == op1.index
  2964.        && ((op1.index != -1 && op0.delta2 == op1.delta2)
  2965.            || op0.pfn == op1.pfn)) */
  2966.  
  2967.       tree index0 = build_component_ref (op0, index_identifier, 0, 0);
  2968.       tree index1 = save_expr (build_component_ref (op1, index_identifier, 0, 0));
  2969.       tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
  2970.       tree pfn1 = PFN_FROM_PTRMEMFUNC (op1);
  2971.       tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
  2972.       tree delta21 = DELTA2_FROM_PTRMEMFUNC (op1);
  2973.       tree e1, e2, e3;
  2974.       tree integer_neg_one_node
  2975.         = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
  2976.       e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
  2977.       e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
  2978.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1);
  2979.       e3 = build_binary_op (EQ_EXPR, pfn0, pfn1, 1);
  2980.       e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
  2981.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
  2982.       if (code == EQ_EXPR)
  2983.         return e2;
  2984.       return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
  2985.     }
  2986.       else if (TYPE_PTRMEMFUNC_P (type0)
  2987.            && TYPE_PTRMEMFUNC_FN_TYPE (type0) == type1)
  2988.     {
  2989.       tree index0 = build_component_ref (op0, index_identifier, 0, 0);
  2990.       tree index1;
  2991.       tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
  2992.       tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
  2993.       tree delta21 = integer_zero_node;
  2994.       tree e1, e2, e3;
  2995.       tree integer_neg_one_node
  2996.         = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
  2997.       if (TREE_CODE (TREE_OPERAND (op1, 0)) == FUNCTION_DECL
  2998.           && DECL_VINDEX (TREE_OPERAND (op1, 0)))
  2999.         {
  3000.           /* Map everything down one to make room for the null pointer to member.  */
  3001.           index1 = size_binop (PLUS_EXPR,
  3002.                    DECL_VINDEX (TREE_OPERAND (op1, 0)),
  3003.                    integer_one_node);
  3004.           op1 = integer_zero_node;
  3005.           delta21 = CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1)));
  3006.           delta21 = DECL_FIELD_BITPOS (delta21);
  3007.           delta21 = size_binop (FLOOR_DIV_EXPR, delta21, size_int (BITS_PER_UNIT));
  3008.         }
  3009.       else
  3010.         index1 = integer_neg_one_node;
  3011.       op1 = build1 (NOP_EXPR, TYPE_PTRMEMFUNC_FN_TYPE (type0), op1);
  3012.       e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
  3013.       e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
  3014.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1);
  3015.       e3 = build_binary_op (EQ_EXPR, pfn0, op1, 1);
  3016.       e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
  3017.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
  3018.       if (code == EQ_EXPR)
  3019.         return e2;
  3020.       return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
  3021.     }
  3022.       else if (TYPE_PTRMEMFUNC_P (type1)
  3023.            && TYPE_PTRMEMFUNC_FN_TYPE (type1) == type0)
  3024.     {
  3025.       return build_binary_op (code, op1, op0, 1);
  3026.     }
  3027.       else
  3028.     /* If args are not valid, clear out RESULT_TYPE
  3029.        to cause an error message later.  */
  3030.     result_type = 0;
  3031.       break;
  3032.  
  3033.     case MAX_EXPR:
  3034.     case MIN_EXPR:
  3035.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3036.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3037.     shorten = 1;
  3038.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  3039.     {
  3040.       if (! comp_target_types (type0, type1, 1))
  3041.         pedwarn ("comparison of distinct pointer types lacks a cast");
  3042.       else if (pedantic
  3043.            && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
  3044.         pedwarn ("ANSI C++ forbids ordered comparisons of pointers to functions");
  3045.       result_type = common_type (type0, type1);
  3046.     }
  3047.       break;
  3048.  
  3049.     case LE_EXPR:
  3050.     case GE_EXPR:
  3051.     case LT_EXPR:
  3052.     case GT_EXPR:
  3053.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3054.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3055.     short_compare = 1;
  3056.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  3057.     {
  3058.       if (! comp_target_types (type0, type1, 1))
  3059.         pedwarn ("comparison of distinct pointer types lacks a cast");
  3060.       else if (pedantic 
  3061.            && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
  3062.         pedwarn ("ANSI C++ forbids ordered comparisons of pointers to functions");
  3063.       result_type = integer_type_node;
  3064.     }
  3065.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  3066.            && integer_zerop (op1))
  3067.     {
  3068.       result_type = integer_type_node;
  3069.       op1 = null_pointer_node;
  3070.       if (! flag_traditional)
  3071.         warning ("ordered comparison of pointer with integer zero");
  3072.     }
  3073.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  3074.            && integer_zerop (op0))
  3075.     {
  3076.       result_type = integer_type_node;
  3077.       op0 = null_pointer_node;
  3078.       if (pedantic)
  3079.         pedwarn ("ANSI C++ forbids ordered comparison of pointer with integer zero");
  3080.     }
  3081.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  3082.     {
  3083.       result_type = integer_type_node;
  3084.       if (pedantic)
  3085.         pedwarn ("ANSI C++ forbids comparison between pointer and integer");
  3086.       else if (! flag_traditional)
  3087.         warning ("comparison between pointer and integer");
  3088.       op1 = convert (TREE_TYPE (op0), op1);
  3089.     }
  3090.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  3091.     {
  3092.       result_type = integer_type_node;
  3093.       if (pedantic)
  3094.         pedwarn ("ANSI C++ forbids comparison between pointer and integer");
  3095.       else if (! flag_traditional)
  3096.         warning ("comparison between pointer and integer");
  3097.       op0 = convert (TREE_TYPE (op1), op0);
  3098.     }
  3099.       converted = 1;
  3100.       break;
  3101.     }
  3102.  
  3103.   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3104.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3105.     {
  3106.       if (shorten || common || short_compare)
  3107.     result_type = common_type (type0, type1);
  3108.  
  3109.       /* For certain operations (which identify themselves by shorten != 0)
  3110.      if both args were extended from the same smaller type,
  3111.      do the arithmetic in that type and then extend.
  3112.  
  3113.      shorten !=0 and !=1 indicates a bitwise operation.
  3114.      For them, this optimization is safe only if
  3115.      both args are zero-extended or both are sign-extended.
  3116.      Otherwise, we might change the result.
  3117.      Eg, (short)-1 | (unsigned short)-1 is (int)-1
  3118.      but calculated in (unsigned short) it would be (unsigned short)-1.  */
  3119.  
  3120.       if (shorten)
  3121.     {
  3122.       int unsigned0, unsigned1;
  3123.       tree arg0 = get_narrower (op0, &unsigned0);
  3124.       tree arg1 = get_narrower (op1, &unsigned1);
  3125.       /* UNS is 1 if the operation to be done is an unsigned one.  */
  3126.       int uns = TREE_UNSIGNED (result_type);
  3127.       tree type;
  3128.  
  3129.       final_type = result_type;
  3130.  
  3131.       /* Handle the case that OP0 does not *contain* a conversion
  3132.          but it *requires* conversion to FINAL_TYPE.  */
  3133.  
  3134.       if (op0 == arg0 && TREE_TYPE (op0) != final_type)
  3135.         unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
  3136.       if (op1 == arg1 && TREE_TYPE (op1) != final_type)
  3137.         unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
  3138.  
  3139.       /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
  3140.  
  3141.       /* For bitwise operations, signedness of nominal type
  3142.          does not matter.  Consider only how operands were extended.  */
  3143.       if (shorten == -1)
  3144.         uns = unsigned0;
  3145.  
  3146.       /* Note that in all three cases below we refrain from optimizing
  3147.          an unsigned operation on sign-extended args.
  3148.          That would not be valid.  */
  3149.  
  3150.       /* Both args variable: if both extended in same way
  3151.          from same width, do it in that width.
  3152.          Do it unsigned if args were zero-extended.  */
  3153.       if ((TYPE_PRECISION (TREE_TYPE (arg0))
  3154.            < TYPE_PRECISION (result_type))
  3155.           && (TYPE_PRECISION (TREE_TYPE (arg1))
  3156.           == TYPE_PRECISION (TREE_TYPE (arg0)))
  3157.           && unsigned0 == unsigned1
  3158.           && (unsigned0 || !uns))
  3159.         result_type
  3160.           = signed_or_unsigned_type (unsigned0,
  3161.                      common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
  3162.       else if (TREE_CODE (arg0) == INTEGER_CST
  3163.            && (unsigned1 || !uns)
  3164.            && (TYPE_PRECISION (TREE_TYPE (arg1))
  3165.                < TYPE_PRECISION (result_type))
  3166.            && (type = signed_or_unsigned_type (unsigned1,
  3167.                                TREE_TYPE (arg1)),
  3168.                int_fits_type_p (arg0, type)))
  3169.         result_type = type;
  3170.       else if (TREE_CODE (arg1) == INTEGER_CST
  3171.            && (unsigned0 || !uns)
  3172.            && (TYPE_PRECISION (TREE_TYPE (arg0))
  3173.                < TYPE_PRECISION (result_type))
  3174.            && (type = signed_or_unsigned_type (unsigned0,
  3175.                                TREE_TYPE (arg0)),
  3176.                int_fits_type_p (arg1, type)))
  3177.         result_type = type;
  3178.     }
  3179.  
  3180.       /* Shifts can be shortened if shifting right.  */
  3181.  
  3182.       if (short_shift)
  3183.     {
  3184.       int unsigned_arg;
  3185.       tree arg0 = get_narrower (op0, &unsigned_arg);
  3186.  
  3187.       final_type = result_type;
  3188.  
  3189.       if (arg0 == op0 && final_type == TREE_TYPE (op0))
  3190.         unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
  3191.  
  3192.       if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
  3193.           /* If arg is sign-extended and then unsigned-shifted,
  3194.          we can simulate this with a signed shift in arg's type
  3195.          only if the extended result is at least twice as wide
  3196.          as the arg.  Otherwise, the shift could use up all the
  3197.          ones made by sign-extension and bring in zeros.
  3198.          We can't optimize that case at all, but in most machines
  3199.          it never happens because available widths are 2**N.  */
  3200.           && (!TREE_UNSIGNED (final_type)
  3201.           || unsigned_arg
  3202.           || ((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0))
  3203.               <= TYPE_PRECISION (result_type))))
  3204.         {
  3205.           /* Do an unsigned shift if the operand was zero-extended.  */
  3206.           result_type
  3207.         = signed_or_unsigned_type (unsigned_arg,
  3208.                        TREE_TYPE (arg0));
  3209.           /* Convert value-to-be-shifted to that type.  */
  3210.           if (TREE_TYPE (op0) != result_type)
  3211.         op0 = convert (result_type, op0);
  3212.           converted = 1;
  3213.         }
  3214.     }
  3215.  
  3216.       /* Comparison operations are shortened too but differently.
  3217.      They identify themselves by setting short_compare = 1.  */
  3218.  
  3219.       if (short_compare)
  3220.     {
  3221.       /* Don't write &op0, etc., because that would prevent op0
  3222.          from being kept in a register.
  3223.          Instead, make copies of the our local variables and
  3224.          pass the copies by reference, then copy them back afterward.  */
  3225.       tree xop0 = op0, xop1 = op1, xresult_type = result_type;
  3226.       enum tree_code xresultcode = resultcode;
  3227.       tree val 
  3228.         = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
  3229.       if (val != 0)
  3230.         return val;
  3231.       op0 = xop0, op1 = xop1, result_type = xresult_type;
  3232.       resultcode = xresultcode;
  3233.     }
  3234.  
  3235.       if (short_compare && extra_warnings)
  3236.     {
  3237.       int unsignedp0, unsignedp1;
  3238.       tree primop0 = get_narrower (op0, &unsignedp0);
  3239.       tree primop1 = get_narrower (op1, &unsignedp1);
  3240.  
  3241.       /* Warn if signed and unsigned are being compared in a size larger
  3242.          than their original size, as this will always fail.  */
  3243.  
  3244.       if (unsignedp0 != unsignedp1
  3245.           && (TYPE_PRECISION (TREE_TYPE (primop0))
  3246.           < TYPE_PRECISION (result_type))
  3247.           && (TYPE_PRECISION (TREE_TYPE (primop1))
  3248.           < TYPE_PRECISION (result_type)))
  3249.         warning ("comparison between promoted unsigned and signed");
  3250.  
  3251.       /* Warn if two unsigned values are being compared in a size
  3252.          larger than their original size, and one (and only one) is the
  3253.          result of a `~' operator.  This comparison will always fail.
  3254.  
  3255.          Also warn if one operand is a constant, and the constant does not
  3256.          have all bits set that are set in the ~ operand when it is
  3257.          extended.  */
  3258.  
  3259.       else if (TREE_CODE (primop0) == BIT_NOT_EXPR
  3260.            ^ TREE_CODE (primop1) == BIT_NOT_EXPR)
  3261.         {
  3262.           if (TREE_CODE (primop0) == BIT_NOT_EXPR)
  3263.         primop0 = get_narrower (TREE_OPERAND (op0, 0), &unsignedp0);
  3264.           if (TREE_CODE (primop1) == BIT_NOT_EXPR)
  3265.         primop1 = get_narrower (TREE_OPERAND (op1, 0), &unsignedp1);
  3266.           
  3267.           if (TREE_CODE (primop0) == INTEGER_CST
  3268.           || TREE_CODE (primop1) == INTEGER_CST)
  3269.         {
  3270.           tree primop;
  3271.           HOST_WIDE_INT constant, mask;
  3272.           int unsignedp;
  3273.           unsigned bits;
  3274.  
  3275.           if (TREE_CODE (primop0) == INTEGER_CST)
  3276.             {
  3277.               primop = primop1;
  3278.               unsignedp = unsignedp1;
  3279.               constant = TREE_INT_CST_LOW (primop0);
  3280.             }
  3281.           else
  3282.             {
  3283.               primop = primop0;
  3284.               unsignedp = unsignedp0;
  3285.               constant = TREE_INT_CST_LOW (primop1);
  3286.             }
  3287.  
  3288.           bits = TYPE_PRECISION (TREE_TYPE (primop));
  3289.           if (bits < TYPE_PRECISION (result_type)
  3290.               && bits < HOST_BITS_PER_LONG && unsignedp)
  3291.             {
  3292.               mask = (~ (HOST_WIDE_INT) 0) << bits;
  3293.               if ((mask & constant) != mask)
  3294.             warning ("comparison of promoted ~unsigned with constant");
  3295.             }
  3296.         }
  3297.           else if (unsignedp0 && unsignedp1
  3298.                && (TYPE_PRECISION (TREE_TYPE (primop0))
  3299.                < TYPE_PRECISION (result_type))
  3300.                && (TYPE_PRECISION (TREE_TYPE (primop1))
  3301.                < TYPE_PRECISION (result_type)))
  3302.         warning ("comparison of promoted ~unsigned with unsigned");
  3303.         }
  3304.     }
  3305.     }
  3306.  
  3307.   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
  3308.      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
  3309.      Then the expression will be built.
  3310.      It will be given type FINAL_TYPE if that is nonzero;
  3311.      otherwise, it will be given type RESULT_TYPE.  */
  3312.  
  3313.   if (!result_type)
  3314.     {
  3315.       binary_op_error (error_code);
  3316.       return error_mark_node;
  3317.     }
  3318.  
  3319.   if (! converted)
  3320.     {
  3321.       if (TREE_TYPE (op0) != result_type)
  3322.     op0 = convert (result_type, op0); 
  3323.       if (TREE_TYPE (op1) != result_type)
  3324.     op1 = convert (result_type, op1); 
  3325.     }
  3326.  
  3327.   {
  3328.     register tree result = build (resultcode, result_type, op0, op1);
  3329.     register tree folded;
  3330.  
  3331.     folded = fold (result);
  3332.     if (folded == result)
  3333.       TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  3334.     if (final_type != 0)
  3335.       return convert (final_type, folded);
  3336.     return folded;
  3337.   }
  3338. }
  3339.  
  3340. /* Return a tree for the sum or difference (RESULTCODE says which)
  3341.    of pointer PTROP and integer INTOP.  */
  3342.  
  3343. static tree
  3344. pointer_int_sum (resultcode, ptrop, intop)
  3345.      enum tree_code resultcode;
  3346.      register tree ptrop, intop;
  3347. {
  3348.   tree size_exp;
  3349.  
  3350.   register tree result;
  3351.   register tree folded = fold (intop);
  3352.  
  3353.   /* The result is a pointer of the same type that is being added.  */
  3354.  
  3355.   register tree result_type = TREE_TYPE (ptrop);
  3356.  
  3357.   /* Needed to make OOPS V2R3 work.  */
  3358.   intop = folded;
  3359.   if (TREE_CODE (intop) == INTEGER_CST
  3360.       && TREE_INT_CST_LOW (intop) == 0
  3361.       && TREE_INT_CST_HIGH (intop) == 0)
  3362.     return ptrop;
  3363.  
  3364.   if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
  3365.     {
  3366.       if (pedantic || warn_pointer_arith)
  3367.     pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
  3368.       size_exp = integer_one_node;
  3369.     }
  3370.   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
  3371.     {
  3372.       if (pedantic || warn_pointer_arith)
  3373.     pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
  3374.       size_exp = integer_one_node;
  3375.     }
  3376.   else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
  3377.     {
  3378.       if (pedantic || warn_pointer_arith)
  3379.     pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
  3380.       size_exp = integer_one_node;
  3381.     }
  3382.   else if (TREE_CODE (TREE_TYPE (result_type)) == OFFSET_TYPE)
  3383.     {
  3384.       if (pedantic)
  3385.     pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
  3386.       size_exp = integer_one_node;
  3387.     }
  3388.   else
  3389.     size_exp = size_in_bytes (TREE_TYPE (result_type));
  3390.  
  3391.   /* If what we are about to multiply by the size of the elements
  3392.      contains a constant term, apply distributive law
  3393.      and multiply that constant term separately.
  3394.      This helps produce common subexpressions.  */
  3395.  
  3396.   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
  3397.       && ! TREE_CONSTANT (intop)
  3398.       && TREE_CONSTANT (TREE_OPERAND (intop, 1))
  3399.       && TREE_CONSTANT (size_exp))
  3400.     {
  3401.       enum tree_code subcode = resultcode;
  3402.       if (TREE_CODE (intop) == MINUS_EXPR)
  3403.     subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
  3404.       ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1), 1);
  3405.       intop = TREE_OPERAND (intop, 0);
  3406.     }
  3407.  
  3408.   /* Convert the integer argument to a type the same size as a pointer
  3409.      so the multiply won't overflow spuriously.  */
  3410.  
  3411.   if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
  3412.     intop = convert (type_for_size (POINTER_SIZE, 0), intop);
  3413.  
  3414.   /* Replace the integer argument
  3415.      with a suitable product by the object size.  */
  3416.  
  3417.   intop = build_binary_op (MULT_EXPR, intop, size_exp, 1);
  3418.  
  3419.   /* Create the sum or difference.  */
  3420.  
  3421.   result = build (resultcode, result_type, ptrop, intop);
  3422.  
  3423.   folded = fold (result);
  3424.   if (folded == result)
  3425.     TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
  3426.   return folded;
  3427. }
  3428.  
  3429. /* Return a tree for the difference of pointers OP0 and OP1.
  3430.    The resulting tree has type int.  */
  3431.  
  3432. static tree
  3433. pointer_diff (op0, op1)
  3434.      register tree op0, op1;
  3435. {
  3436.   register tree result, folded;
  3437.   tree restype = ptrdiff_type_node;
  3438.   tree target_type = TREE_TYPE (TREE_TYPE (op0));
  3439.  
  3440.   if (pedantic)
  3441.     {
  3442.       if (TREE_CODE (target_type) == VOID_TYPE)
  3443.     pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
  3444.       if (TREE_CODE (target_type) == FUNCTION_TYPE)
  3445.     pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
  3446.       if (TREE_CODE (target_type) == METHOD_TYPE)
  3447.     pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
  3448.       if (TREE_CODE (target_type) == OFFSET_TYPE)
  3449.     pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
  3450.     }
  3451.  
  3452.   /* First do the subtraction as integers;
  3453.      then drop through to build the divide operator.  */
  3454.  
  3455.   op0 = build_binary_op (MINUS_EXPR,
  3456.              convert (restype, op0), convert (restype, op1), 1);
  3457.  
  3458.   /* This generates an error if op1 is a pointer to an incomplete type.  */
  3459.   if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
  3460.     error ("arithmetic on pointer to an incomplete type");
  3461.  
  3462.   op1 = ((TREE_CODE (target_type) == VOID_TYPE
  3463.       || TREE_CODE (target_type) == FUNCTION_TYPE
  3464.       || TREE_CODE (target_type) == METHOD_TYPE
  3465.       || TREE_CODE (target_type) == OFFSET_TYPE)
  3466.      ? integer_one_node
  3467.      : size_in_bytes (target_type));
  3468.  
  3469.   /* Do the division.  */
  3470.  
  3471.   result = build (EXACT_DIV_EXPR, restype, op0, op1);
  3472.  
  3473.   folded = fold (result);
  3474.   if (folded == result)
  3475.     TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  3476.   return folded;
  3477. }
  3478.  
  3479. /* Handle the case of taking the address of a COMPONENT_REF.
  3480.    Called by `build_unary_op' and `build_up_reference'.
  3481.  
  3482.    ARG is the COMPONENT_REF whose address we want.
  3483.    ARGTYPE is the pointer type that this address should have.
  3484.    MSG is an error message to print if this COMPONENT_REF is not
  3485.    addressable (such as a bitfield).  */
  3486.  
  3487. tree
  3488. build_component_addr (arg, argtype, msg)
  3489.      tree arg, argtype;
  3490.      char *msg;
  3491. {
  3492.   tree field = TREE_OPERAND (arg, 1);
  3493.   tree basetype = decl_type_context (field);
  3494.   tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  3495.  
  3496.   if (DECL_BIT_FIELD (field))
  3497.     {
  3498.       error (msg, IDENTIFIER_POINTER (DECL_NAME (field)));
  3499.       return error_mark_node;
  3500.     }
  3501.  
  3502.   if (flag_gc)
  3503.     cp_warning ("address of `%T::%D' taken", basetype, field);
  3504.  
  3505.   if (TREE_CODE (field) == FIELD_DECL
  3506.       && TYPE_USES_COMPLEX_INHERITANCE (basetype))
  3507.     /* Can't convert directly to ARGTYPE, since that
  3508.        may have the same pointer type as one of our
  3509.        baseclasses.  */
  3510.     rval = build1 (NOP_EXPR, argtype,
  3511.            convert_pointer_to (basetype, rval));
  3512.   else
  3513.     /* This conversion is harmless.  */
  3514.     rval = convert (argtype, rval);
  3515.  
  3516.   if (! integer_zerop (DECL_FIELD_BITPOS (field)))
  3517.     {
  3518.       tree offset = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
  3519.                 size_int (BITS_PER_UNIT));
  3520.       int flag = TREE_CONSTANT (rval);
  3521.       rval = fold (build (PLUS_EXPR, argtype,
  3522.               rval, convert (argtype, offset)));
  3523.       TREE_CONSTANT (rval) = flag;
  3524.     }
  3525.   return rval;
  3526. }
  3527.    
  3528. /* Construct and perhaps optimize a tree representation
  3529.    for a unary operation.  CODE, a tree_code, specifies the operation
  3530.    and XARG is the operand.  */
  3531.  
  3532. tree
  3533. build_x_unary_op (code, xarg)
  3534.      enum tree_code code;
  3535.      tree xarg;
  3536. {
  3537.   tree rval;
  3538.  
  3539.   /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
  3540.      error message. */
  3541.   if (code != ADDR_EXPR || TREE_CODE (TREE_TYPE (xarg)) != RECORD_TYPE
  3542.       || TYPE_SIZE (TREE_TYPE (xarg)))
  3543.     {
  3544.       /* See comments in `build_x_unary_op'.  */
  3545.       if (rval = build_opfncall (code, 0, xarg, NULL_TREE, NULL_TREE))
  3546.     {
  3547.       if (rval = build_opfncall (code, LOOKUP_PROTECT, xarg, NULL_TREE, NULL_TREE))
  3548.         return rval;
  3549.       build_opfncall (code, LOOKUP_NORMAL, xarg, NULL_TREE, NULL_TREE);
  3550.       return error_mark_node;
  3551.     }
  3552.     }
  3553.   return build_unary_op (code, xarg, 0);
  3554. }
  3555.  
  3556. /* C++: Must handle pointers to members.
  3557.  
  3558.    Perhaps type instantiation should be extended to handle conversion
  3559.    from aggregates to types we don't yet know we want?  (Or are those
  3560.    cases typically errors which should be reported?)
  3561.  
  3562.    NOCONVERT nonzero suppresses the default promotions
  3563.    (such as from short to int).  */
  3564. tree
  3565. build_unary_op (code, xarg, noconvert)
  3566.      enum tree_code code;
  3567.      tree xarg;
  3568.      int noconvert;
  3569. {
  3570.   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
  3571.   register tree arg = xarg;
  3572.   register tree argtype = 0;
  3573.   register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
  3574.   char *errstring = NULL;
  3575.   tree val;
  3576.   int isaggrtype;
  3577.  
  3578.   if (typecode == ERROR_MARK)
  3579.     return error_mark_node;
  3580.  
  3581.   if (typecode == REFERENCE_TYPE && code != ADDR_EXPR && ! noconvert)
  3582.     {
  3583.       arg = convert_from_reference (arg);
  3584.       typecode = TREE_CODE (TREE_TYPE (arg));
  3585.     }
  3586.  
  3587.   if (typecode == ENUMERAL_TYPE)
  3588.     typecode = INTEGER_TYPE;
  3589.  
  3590.   isaggrtype = IS_AGGR_TYPE_CODE (typecode);
  3591.  
  3592.   switch (code)
  3593.     {
  3594.     case CONVERT_EXPR:
  3595.       /* This is used for unary plus, because a CONVERT_EXPR
  3596.      is enough to prevent anybody from looking inside for
  3597.      associativity, but won't generate any code.  */
  3598.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  3599.         errstring = "wrong type argument to unary plus";
  3600.       else if (!noconvert)
  3601.     arg = default_conversion (arg);
  3602.       break;
  3603.  
  3604.     case NEGATE_EXPR:
  3605.       if (isaggrtype)
  3606.     {
  3607.       if (!noconvert)
  3608.         arg = default_conversion (arg);
  3609.       else
  3610.         {
  3611.           cp_error ("type conversion for type `%T' not allowed",
  3612.               TREE_TYPE (arg));
  3613.           return error_mark_node;
  3614.         }
  3615.       typecode = TREE_CODE (TREE_TYPE (arg));
  3616.       noconvert = 1;
  3617.     }
  3618.  
  3619.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  3620.         errstring = "wrong type argument to unary minus";
  3621.       else if (!noconvert)
  3622.     arg = default_conversion (arg);
  3623.       break;
  3624.  
  3625.     case BIT_NOT_EXPR:
  3626.       if (isaggrtype)
  3627.     {
  3628.       if (!noconvert)
  3629.         arg = default_conversion (arg);
  3630.       else
  3631.         {
  3632.           cp_error ("type conversion for type `%T' not allowed",
  3633.               TREE_TYPE (arg));
  3634.           return error_mark_node;
  3635.         }
  3636.       typecode = TREE_CODE (TREE_TYPE (arg));
  3637.       noconvert = 1;
  3638.     }
  3639.  
  3640.       if (typecode != INTEGER_TYPE)
  3641.         errstring = "wrong type argument to bit-complement";
  3642.       else if (!noconvert)
  3643.     arg = default_conversion (arg);
  3644.       break;
  3645.  
  3646.     case ABS_EXPR:
  3647.       if (isaggrtype)
  3648.     {
  3649.       if (!noconvert)
  3650.         arg = default_conversion (arg);
  3651.       else
  3652.         {
  3653.           cp_error ("type conversion for type `%T' not allowed",
  3654.               TREE_TYPE (arg));
  3655.           return error_mark_node;
  3656.         }
  3657.       typecode = TREE_CODE (TREE_TYPE (arg));
  3658.       noconvert = 1;
  3659.     }
  3660.  
  3661.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  3662.         errstring = "wrong type argument to abs";
  3663.       else if (!noconvert)
  3664.     arg = default_conversion (arg);
  3665.       break;
  3666.  
  3667.     case TRUTH_NOT_EXPR:
  3668.       if (isaggrtype)
  3669.     {
  3670.       arg = truthvalue_conversion (arg);
  3671.       typecode = TREE_CODE (TREE_TYPE (arg));
  3672.     }
  3673.  
  3674.       if (typecode != INTEGER_TYPE
  3675.       && typecode != REAL_TYPE && typecode != POINTER_TYPE
  3676.       /* These will convert to a pointer.  */
  3677.       && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
  3678.     {
  3679.       errstring = "wrong type argument to unary exclamation mark";
  3680.       break;
  3681.     }
  3682.       arg = truthvalue_conversion (arg);
  3683.       val = invert_truthvalue (arg);
  3684.       if (val) return val;
  3685.       break;
  3686.  
  3687.     case NOP_EXPR:
  3688.       break;
  3689.       
  3690.     case PREINCREMENT_EXPR:
  3691.     case POSTINCREMENT_EXPR:
  3692.     case PREDECREMENT_EXPR:
  3693.     case POSTDECREMENT_EXPR:
  3694.       /* Handle complex lvalues (when permitted)
  3695.      by reduction to simpler cases.  */
  3696.  
  3697.       val = unary_complex_lvalue (code, arg);
  3698.       if (val != 0)
  3699.     return val;
  3700.  
  3701.       /* Report invalid types.  */
  3702.  
  3703.       if (isaggrtype)
  3704.     {
  3705.       arg = default_conversion (arg);
  3706.       typecode = TREE_CODE (TREE_TYPE (arg));
  3707.     }
  3708.  
  3709.       if (typecode != POINTER_TYPE
  3710.       && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
  3711.     {
  3712.       if (code == PREINCREMENT_EXPR)
  3713.         errstring ="no pre-increment operator for type";
  3714.       else if (code == POSTINCREMENT_EXPR)
  3715.         errstring ="no post-increment operator for type";
  3716.       else if (code == PREDECREMENT_EXPR)
  3717.         errstring ="no pre-decrement operator for type";
  3718.       else
  3719.         errstring ="no post-decrement operator for type";
  3720.       break;
  3721.     }
  3722.  
  3723.       /* Report something read-only.  */
  3724.  
  3725.       if (TYPE_READONLY (TREE_TYPE (arg))
  3726.       || TREE_READONLY (arg))
  3727.     readonly_error (arg, ((code == PREINCREMENT_EXPR
  3728.                    || code == POSTINCREMENT_EXPR)
  3729.                   ? "increment" : "decrement"),
  3730.             0);
  3731.  
  3732.       {
  3733.     register tree inc;
  3734.     tree result_type = TREE_TYPE (arg);
  3735.  
  3736.     arg = get_unwidened (arg, 0);
  3737.     argtype = TREE_TYPE (arg);
  3738.  
  3739.     /* ARM $5.2.5 last annotation says this should be forbidden.  */
  3740.     if (TREE_CODE (argtype) == ENUMERAL_TYPE)
  3741.       pedwarn ("ANSI C++ forbids %sing an enum",
  3742.            (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
  3743.            ? "increment" : "decrement");
  3744.         
  3745.     /* Compute the increment.  */
  3746.  
  3747.     if (typecode == POINTER_TYPE)
  3748.       {
  3749.         enum tree_code tmp = TREE_CODE (TREE_TYPE (argtype));
  3750.         if (tmp == FUNCTION_TYPE || tmp == METHOD_TYPE
  3751.         || tmp == VOID_TYPE || tmp == OFFSET_TYPE)
  3752.           cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
  3753.                 ((code == PREINCREMENT_EXPR
  3754.                   || code == POSTINCREMENT_EXPR)
  3755.                  ? "increment" : "decrement"), argtype);
  3756.         inc = c_sizeof_nowarn (TREE_TYPE (argtype));
  3757.       }
  3758.     else
  3759.       inc = integer_one_node;
  3760.  
  3761.     inc = convert (argtype, inc);
  3762.  
  3763.     /* Handle incrementing a cast-expression.  */
  3764.  
  3765.     switch (TREE_CODE (arg))
  3766.       {
  3767.       case NOP_EXPR:
  3768.       case CONVERT_EXPR:
  3769.       case FLOAT_EXPR:
  3770.       case FIX_TRUNC_EXPR:
  3771.       case FIX_FLOOR_EXPR:
  3772.       case FIX_ROUND_EXPR:
  3773.       case FIX_CEIL_EXPR:
  3774.         {
  3775.           tree incremented, modify, value;
  3776.           pedantic_lvalue_warning (CONVERT_EXPR);
  3777.           arg = stabilize_reference (arg);
  3778.           if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
  3779.         value = arg;
  3780.           else
  3781.         value = save_expr (arg);
  3782.           incremented = build (((code == PREINCREMENT_EXPR
  3783.                      || code == POSTINCREMENT_EXPR)
  3784.                     ? PLUS_EXPR : MINUS_EXPR),
  3785.                    argtype, value, inc);
  3786.           TREE_SIDE_EFFECTS (incremented) = 1;
  3787.           modify = build_modify_expr (arg, NOP_EXPR, incremented);
  3788.           return build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
  3789.         }
  3790.       }
  3791.  
  3792.     if (TREE_CODE (arg) == OFFSET_REF)
  3793.       arg = resolve_offset_ref (arg);
  3794.  
  3795.     /* Complain about anything else that is not a true lvalue.  */
  3796.     if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
  3797.                     || code == POSTINCREMENT_EXPR)
  3798.                    ? "increment" : "decrement")))
  3799.       return error_mark_node;
  3800.  
  3801.     val = build (code, TREE_TYPE (arg), arg, inc);
  3802.     TREE_SIDE_EFFECTS (val) = 1;
  3803.     return convert (result_type, val);
  3804.       }
  3805.  
  3806.     case ADDR_EXPR:
  3807.       /* Note that this operation never does default_conversion
  3808.      regardless of NOCONVERT.  */
  3809.  
  3810.       if (TREE_REFERENCE_EXPR (arg))
  3811.     {
  3812.       error ("references are not lvalues");
  3813.       return error_mark_node;
  3814.     }
  3815.       else if (typecode == REFERENCE_TYPE)
  3816.     {
  3817.       arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
  3818.       TREE_REFERENCE_EXPR (arg) = 1;
  3819.       return arg;
  3820.     }
  3821.       else if (TREE_CODE (arg) == FUNCTION_DECL
  3822.            && DECL_NAME (arg)
  3823.            && DECL_CONTEXT (arg) == NULL_TREE
  3824.            && IDENTIFIER_LENGTH (DECL_NAME (arg)) == 4
  3825.            && IDENTIFIER_POINTER (DECL_NAME (arg))[0] == 'm'
  3826.            && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg)), "main"))
  3827.     {
  3828.       /* ARM $3.4 */
  3829.       error ("attempt to take address of function `main'");
  3830.       return error_mark_node;
  3831.     }
  3832.  
  3833.       /* Let &* cancel out to simplify resulting code.  */
  3834.       if (TREE_CODE (arg) == INDIRECT_REF)
  3835.     {
  3836.       /* We don't need to have `current_class_decl' wrapped in a
  3837.          NON_LVALUE_EXPR node.  */
  3838.       if (arg == C_C_D)
  3839.         return current_class_decl;
  3840.  
  3841.       /* Keep `default_conversion' from converting if
  3842.          ARG is of REFERENCE_TYPE.  */
  3843.       arg = TREE_OPERAND (arg, 0);
  3844.       if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE)
  3845.         {
  3846.           if (TREE_CODE (arg) == VAR_DECL && DECL_INITIAL (arg)
  3847.           && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg)))
  3848.         arg = DECL_INITIAL (arg);
  3849.           arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
  3850.           TREE_REFERENCE_EXPR (arg) = 1;
  3851.           TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
  3852.         }
  3853.       else if (lvalue_p (arg))
  3854.         /* Don't let this be an lvalue.  */
  3855.         return non_lvalue (arg);
  3856.       return arg;
  3857.     }
  3858.  
  3859.       /* For &x[y], return x+y */
  3860.       if (TREE_CODE (arg) == ARRAY_REF)
  3861.     {
  3862.       if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
  3863.         return error_mark_node;
  3864.       return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
  3865.                   TREE_OPERAND (arg, 1), 1);
  3866.     }
  3867.  
  3868.       /* For &(++foo), we are really taking the address of the variable
  3869.      being acted upon by the increment/decrement operator.  ARM $5.3.1
  3870.      However, according to ARM $5.2.5, we don't allow postfix ++ and
  3871.      --, since the prefix operators return lvalues, but the postfix
  3872.      operators do not.  */
  3873.       if (TREE_CODE (arg) == PREINCREMENT_EXPR
  3874.       || TREE_CODE (arg) == PREDECREMENT_EXPR)
  3875.     arg = TREE_OPERAND (arg, 0);
  3876.  
  3877.       /* Uninstantiated types are all functions.  Taking the
  3878.      address of a function is a no-op, so just return the
  3879.      argument.  */
  3880.  
  3881.       if (TREE_CODE (arg) == IDENTIFIER_NODE
  3882.       && IDENTIFIER_OPNAME_P (arg))
  3883.     {
  3884.       my_friendly_abort (117);
  3885.       /* We don't know the type yet, so just work around the problem.
  3886.          We know that this will resolve to an lvalue.  */
  3887.       return build1 (ADDR_EXPR, unknown_type_node, arg);
  3888.     }
  3889.  
  3890.       if (TREE_CODE (arg) == TREE_LIST)
  3891.     {
  3892.       /* Look at methods with only this name.  */
  3893.       if (TREE_CODE (TREE_VALUE (arg)) == FUNCTION_DECL)
  3894.         {
  3895.           tree targ = TREE_VALUE (arg);
  3896.  
  3897.           /* If this function is unique, or it is a unique
  3898.          constructor, we can take its address easily.  */
  3899.           if (DECL_CHAIN (targ) == NULL_TREE
  3900.           || (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (targ))
  3901.               && DECL_CHAIN (DECL_CHAIN (targ)) == NULL_TREE))
  3902.         {
  3903.           if (DECL_CHAIN (targ))
  3904.             targ = DECL_CHAIN (targ);
  3905.           if (DECL_CLASS_CONTEXT (targ))
  3906.             targ = build (OFFSET_REF, TREE_TYPE (targ), C_C_D, targ);
  3907.  
  3908.           val = unary_complex_lvalue (ADDR_EXPR, targ);
  3909.           if (val)
  3910.             return val;
  3911.         }
  3912.  
  3913.           /* This possible setting of TREE_CONSTANT is what makes it possible
  3914.          with an initializer list to emit the entire thing in the data
  3915.          section, rather than a run-time initialization.  */
  3916.           arg = build1 (ADDR_EXPR, unknown_type_node, arg);
  3917.           if (staticp (targ))
  3918.         TREE_CONSTANT (arg) = 1;
  3919.           return arg;
  3920.         }
  3921.       if (TREE_CHAIN (arg) == NULL_TREE
  3922.           && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg))) == NULL_TREE)
  3923.         {
  3924.           /* Unique overloaded member function.  */
  3925.           return build_unary_op (ADDR_EXPR, TREE_VALUE (TREE_VALUE (arg)), 0);
  3926.         }
  3927.       return build1 (ADDR_EXPR, unknown_type_node, arg);
  3928.     }
  3929.  
  3930.       /* Handle complex lvalues (when permitted)
  3931.      by reduction to simpler cases.  */
  3932.       val = unary_complex_lvalue (code, arg);
  3933.       if (val != 0)
  3934.     return val;
  3935.  
  3936. #if 0 /* Turned off because inconsistent;
  3937.      float f; *&(int)f = 3.4 stores in int format
  3938.      whereas (int)f = 3.4 stores in float format.  */
  3939.       /* Address of a cast is just a cast of the address
  3940.      of the operand of the cast.  */
  3941.       switch (TREE_CODE (arg))
  3942.     {
  3943.     case NOP_EXPR:
  3944.     case CONVERT_EXPR:
  3945.     case FLOAT_EXPR:
  3946.     case FIX_TRUNC_EXPR:
  3947.     case FIX_FLOOR_EXPR:
  3948.     case FIX_ROUND_EXPR:
  3949.     case FIX_CEIL_EXPR:
  3950.       if (pedantic)
  3951.         pedwarn ("ANSI C++ forbids taking the address of a cast expression");
  3952.       return convert (build_pointer_type (TREE_TYPE (arg)),
  3953.               build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0));
  3954.     }
  3955. #endif
  3956.  
  3957.       /* Allow the address of a constructor if all the elements
  3958.      are constant.  */
  3959.       if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
  3960.     ;
  3961.       /* Anything not already handled and not a true memory reference
  3962.      is an error.  */
  3963.       else if (typecode != FUNCTION_TYPE
  3964.            && typecode != METHOD_TYPE
  3965.            && !lvalue_or_else (arg, "unary `&'"))
  3966.     return error_mark_node;
  3967.  
  3968.       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
  3969.       argtype = TREE_TYPE (arg);
  3970.       /* If the lvalue is const or volatile,
  3971.      merge that into the type that the address will point to.  */
  3972.       if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
  3973.       || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
  3974.     {
  3975.       if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
  3976.         argtype = build_type_variant (argtype,
  3977.                       TREE_READONLY (arg),
  3978.                       TREE_THIS_VOLATILE (arg));
  3979.     }
  3980.  
  3981.       argtype = build_pointer_type (argtype);
  3982.  
  3983.       if (mark_addressable (arg) == 0)
  3984.     return error_mark_node;
  3985.  
  3986.       {
  3987.     tree addr;
  3988.  
  3989.     if (TREE_CODE (arg) == COMPONENT_REF)
  3990.       addr = build_component_addr (arg, argtype,
  3991.                        "attempt to take address of bit-field structure member `%s'");
  3992.     else
  3993.       addr = build1 (code, argtype, arg);
  3994.  
  3995.     /* Address of a static or external variable or
  3996.        function counts as a constant */
  3997.     if (staticp (arg))
  3998.       TREE_CONSTANT (addr) = 1;
  3999.     return addr;
  4000.       }
  4001.     }
  4002.  
  4003.   if (!errstring)
  4004.     {
  4005.       if (argtype == 0)
  4006.     argtype = TREE_TYPE (arg);
  4007.       return fold (build1 (code, argtype, arg));
  4008.     }
  4009.  
  4010.   error (errstring);
  4011.   return error_mark_node;
  4012. }
  4013.  
  4014. /* If CONVERSIONS is a conversion expression or a nested sequence of such,
  4015.    convert ARG with the same conversions in the same order
  4016.    and return the result.  */
  4017.  
  4018. static tree
  4019. convert_sequence (conversions, arg)
  4020.      tree conversions;
  4021.      tree arg;
  4022. {
  4023.   switch (TREE_CODE (conversions))
  4024.     {
  4025.     case NOP_EXPR:
  4026.     case CONVERT_EXPR:
  4027.     case FLOAT_EXPR:
  4028.     case FIX_TRUNC_EXPR:
  4029.     case FIX_FLOOR_EXPR:
  4030.     case FIX_ROUND_EXPR:
  4031.     case FIX_CEIL_EXPR:
  4032.       return convert (TREE_TYPE (conversions),
  4033.               convert_sequence (TREE_OPERAND (conversions, 0),
  4034.                     arg));
  4035.  
  4036.     default:
  4037.       return arg;
  4038.     }
  4039. }
  4040.  
  4041. /* Apply unary lvalue-demanding operator CODE to the expression ARG
  4042.    for certain kinds of expressions which are not really lvalues
  4043.    but which we can accept as lvalues.
  4044.  
  4045.    If ARG is not a kind of expression we can handle, return zero.  */
  4046.    
  4047. tree
  4048. unary_complex_lvalue (code, arg)
  4049.      enum tree_code code;
  4050.      tree arg;
  4051. {
  4052.   /* Handle (a, b) used as an "lvalue".  */
  4053.   if (TREE_CODE (arg) == COMPOUND_EXPR)
  4054.     {
  4055.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
  4056.       pedantic_lvalue_warning (COMPOUND_EXPR);
  4057.       return build (COMPOUND_EXPR, TREE_TYPE (real_result),
  4058.             TREE_OPERAND (arg, 0), real_result);
  4059.     }
  4060.  
  4061.   /* Handle (a ? b : c) used as an "lvalue".  */
  4062.   if (TREE_CODE (arg) == COND_EXPR)
  4063.     {
  4064.       pedantic_lvalue_warning (COND_EXPR);
  4065.       return (build_conditional_expr
  4066.           (TREE_OPERAND (arg, 0),
  4067.            build_unary_op (code, TREE_OPERAND (arg, 1), 0),
  4068.            build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
  4069.     }
  4070.  
  4071.   if (code != ADDR_EXPR)
  4072.     return 0;
  4073.  
  4074.   /* Handle (a = b) used as an "lvalue" for `&'.  */
  4075.   if (TREE_CODE (arg) == MODIFY_EXPR
  4076.       || TREE_CODE (arg) == INIT_EXPR)
  4077.     {
  4078.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0);
  4079.       return build (COMPOUND_EXPR, TREE_TYPE (real_result), arg, real_result);
  4080.     }
  4081.  
  4082.   if (TREE_CODE (arg) == WITH_CLEANUP_EXPR)
  4083.     {
  4084.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0);
  4085.       real_result = build (WITH_CLEANUP_EXPR, TREE_TYPE (real_result),
  4086.                real_result, 0, TREE_OPERAND (arg, 2));
  4087.       return real_result;
  4088.     }
  4089.  
  4090.   if (TREE_CODE (TREE_TYPE (arg)) == FUNCTION_TYPE
  4091.       || TREE_CODE (TREE_TYPE (arg)) == METHOD_TYPE
  4092.       || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE)
  4093.     {
  4094.       /* The representation of something of type OFFSET_TYPE
  4095.      is really the representation of a pointer to it.
  4096.      Here give the representation its true type.  */
  4097.       tree t;
  4098.       tree offset;
  4099.  
  4100.       my_friendly_assert (TREE_CODE (arg) != SCOPE_REF, 313);
  4101.  
  4102.       if (TREE_CODE (arg) != OFFSET_REF)
  4103.     return 0;
  4104.  
  4105.       t = TREE_OPERAND (arg, 1);
  4106.  
  4107.       if (TREE_CODE (t) == FUNCTION_DECL) /* Check all this code for right semantics. */
  4108.     return build_unary_op (ADDR_EXPR, t, 0);
  4109.       if (TREE_CODE (t) == VAR_DECL)
  4110.     return build_unary_op (ADDR_EXPR, t, 0);
  4111.       else
  4112.     {
  4113.       /* Can't build a pointer to member if the member must
  4114.          go through virtual base classes.  */
  4115.       if (virtual_member (DECL_FIELD_CONTEXT (t),
  4116.                   CLASSTYPE_VBASECLASSES (TREE_TYPE (TREE_OPERAND (arg, 0)))))
  4117.         {
  4118.           sorry ("pointer to member via virtual baseclass");
  4119.           return error_mark_node;
  4120.         }
  4121.  
  4122.       if (TREE_OPERAND (arg, 0)
  4123.           && (TREE_CODE (TREE_OPERAND (arg, 0)) != NOP_EXPR
  4124.           || TREE_OPERAND (TREE_OPERAND (arg, 0), 0) != error_mark_node))
  4125.         {
  4126.           /* Don't know if this should return address to just
  4127.          _DECL, or actual address resolved in this expression.  */
  4128.           sorry ("address of bound pointer-to-member expression");
  4129.           return error_mark_node;
  4130.         }
  4131.  
  4132.       return convert (build_pointer_type (TREE_TYPE (arg)),
  4133.               size_binop (EASY_DIV_EXPR, 
  4134.                       DECL_FIELD_BITPOS (t),
  4135.                       size_int (BITS_PER_UNIT)));
  4136.     }
  4137.     }
  4138.  
  4139.   if (TREE_CODE (arg) == OFFSET_REF)
  4140.     {
  4141.       tree left = TREE_OPERAND (arg, 0), left_addr;
  4142.       tree right_addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 1), 0);
  4143.  
  4144.       if (left == 0)
  4145.     if (current_class_decl)
  4146.       left_addr = current_class_decl;
  4147.     else
  4148.       {
  4149.         error ("no `this' for pointer to member");
  4150.         return error_mark_node;
  4151.       }
  4152.       else
  4153.     left_addr = build_unary_op (ADDR_EXPR, left, 0);
  4154.  
  4155.       return build (PLUS_EXPR, build_pointer_type (TREE_TYPE (arg)),
  4156.             build1 (NOP_EXPR, integer_type_node, left_addr),
  4157.             build1 (NOP_EXPR, integer_type_node, right_addr));
  4158.     }
  4159.  
  4160.   /* We permit compiler to make function calls returning
  4161.      objects of aggregate type look like lvalues.  */
  4162.   {
  4163.     tree targ = arg;
  4164.  
  4165.     if (TREE_CODE (targ) == SAVE_EXPR)
  4166.       targ = TREE_OPERAND (targ, 0);
  4167.  
  4168.     if (TREE_CODE (targ) == CALL_EXPR && IS_AGGR_TYPE (TREE_TYPE (targ)))
  4169.       {
  4170.     if (TREE_CODE (arg) == SAVE_EXPR)
  4171.       targ = arg;
  4172.     else
  4173.       targ = build_cplus_new (TREE_TYPE (arg), arg, 1);
  4174.     return build1 (ADDR_EXPR, TYPE_POINTER_TO (TREE_TYPE (arg)), targ);
  4175.       }
  4176.  
  4177.     if (TREE_CODE (arg) == SAVE_EXPR && TREE_CODE (targ) == INDIRECT_REF)
  4178.       return build (SAVE_EXPR, TYPE_POINTER_TO (TREE_TYPE (arg)),
  4179.              TREE_OPERAND (targ, 0), current_function_decl, NULL);
  4180.  
  4181.     /* We shouldn't wrap WITH_CLEANUP_EXPRs inside of SAVE_EXPRs, but in case
  4182.        we do, here's how to handle it.  */
  4183.     if (TREE_CODE (arg) == SAVE_EXPR && TREE_CODE (targ) == WITH_CLEANUP_EXPR)
  4184.       {
  4185. #if 0
  4186.     /* Not really a bug, but something to turn on when testing.  */
  4187.     compiler_error ("WITH_CLEANUP_EXPR wrapped in SAVE_EXPR");
  4188. #endif
  4189.     return unary_complex_lvalue (ADDR_EXPR, targ);
  4190.       }
  4191.   }
  4192.  
  4193.   /* Don't let anything else be handled specially.  */
  4194.   return 0;
  4195. }
  4196.  
  4197. /* If pedantic, warn about improper lvalue.   CODE is either COND_EXPR
  4198.    COMPOUND_EXPR, or CONVERT_EXPR (for casts).  */
  4199.  
  4200. static void
  4201. pedantic_lvalue_warning (code)
  4202.      enum tree_code code;
  4203. {
  4204.   if (pedantic)
  4205.     pedwarn ("ANSI C++ forbids use of %s expressions as lvalues",
  4206.          code == COND_EXPR ? "conditional"
  4207.          : code == COMPOUND_EXPR ? "compound" : "cast");
  4208. }
  4209.  
  4210. /* Mark EXP saying that we need to be able to take the
  4211.    address of it; it should not be allocated in a register.
  4212.    Value is 1 if successful.
  4213.  
  4214.    C++: we do not allow `current_class_decl' to be addressable.  */
  4215.  
  4216. int
  4217. mark_addressable (exp)
  4218.      tree exp;
  4219. {
  4220.   register tree x = exp;
  4221.  
  4222.   if (TREE_ADDRESSABLE (x) == 1)
  4223.     return 1;
  4224.  
  4225.   while (1)
  4226.     switch (TREE_CODE (x))
  4227.       {
  4228.       case ADDR_EXPR:
  4229.       case COMPONENT_REF:
  4230.       case ARRAY_REF:
  4231.     x = TREE_OPERAND (x, 0);
  4232.     break;
  4233.  
  4234.       case PARM_DECL:
  4235.     if (x == current_class_decl)
  4236.       {
  4237.         error ("address of `this' not available");
  4238.         TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later */
  4239.         put_var_into_stack (x);
  4240.         return 1;
  4241.       }
  4242.       case VAR_DECL:
  4243.     if (TREE_STATIC (x)
  4244.         && TREE_READONLY (x)
  4245.         && DECL_RTL (x) != 0
  4246.         && ! decl_in_memory_p (x))
  4247.       {
  4248.         /* We thought this would make a good constant variable,
  4249.            but we were wrong.  */
  4250.         push_obstacks_nochange ();
  4251.         end_temporary_allocation ();
  4252.  
  4253.         TREE_ASM_WRITTEN (x) = 0;
  4254.         DECL_RTL (x) = 0;
  4255.         rest_of_decl_compilation (x, 0, IDENTIFIER_LOCAL_VALUE (x) == 0, 0);
  4256.         TREE_ADDRESSABLE (x) = 1;
  4257.  
  4258.         pop_obstacks ();
  4259.  
  4260.         return 1;
  4261.       }
  4262.     /* Caller should not be trying to mark initialized
  4263.        constant fields addressable.  */
  4264.     my_friendly_assert (DECL_LANG_SPECIFIC (x) == 0
  4265.                 || DECL_IN_AGGR_P (x) == 0
  4266.                 || TREE_STATIC (x)
  4267.                 || DECL_EXTERNAL (x), 314);
  4268.  
  4269.       case CONST_DECL:
  4270.       case RESULT_DECL:
  4271.     /* For C++, we don't warn about taking the address of a register
  4272.        variable for CONST_DECLs; ARM p97 explicitly says it's okay.  */
  4273.     put_var_into_stack (x);
  4274.     TREE_ADDRESSABLE (x) = 1;
  4275.     return 1;
  4276.  
  4277.       case FUNCTION_DECL:
  4278.     /* We have to test both conditions here.  The first may
  4279.        be non-zero in the case of processing a default function.
  4280.        The second may be non-zero in the case of a template function.  */
  4281.     x = DECL_MAIN_VARIANT (x);
  4282.     if ((DECL_INLINE (x) || DECL_PENDING_INLINE_INFO (x))
  4283.         && (DECL_CONTEXT (x) == NULL_TREE
  4284.         || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x))) != 't'
  4285.         || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x))))
  4286.       {
  4287.         mark_inline_for_output (x);
  4288.         if (x == current_function_decl)
  4289.           DECL_EXTERNAL (x) = 0;
  4290.       }
  4291.     TREE_ADDRESSABLE (x) = 1;
  4292.     TREE_USED (x) = 1;
  4293.     TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
  4294.     return 1;
  4295.  
  4296.       default:
  4297.     return 1;
  4298.     }
  4299. }
  4300.  
  4301. /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
  4302.  
  4303. tree
  4304. build_x_conditional_expr (ifexp, op1, op2)
  4305.      tree ifexp, op1, op2;
  4306. {
  4307.   tree rval;
  4308.  
  4309.   /* See comments in `build_x_binary_op'.  */
  4310.   if (op1 != 0 && (rval = build_opfncall (COND_EXPR, 0, ifexp, op1, op2)))
  4311.     {
  4312.       if (rval = build_opfncall (COND_EXPR, LOOKUP_PROTECT, ifexp, op1, op2))
  4313.     return rval;
  4314.       build_opfncall (COND_EXPR, LOOKUP_NORMAL, ifexp, op1, op2);
  4315.       return error_mark_node;
  4316.     }
  4317.   return build_conditional_expr (ifexp, op1, op2);
  4318. }
  4319.  
  4320. tree
  4321. build_conditional_expr (ifexp, op1, op2)
  4322.      tree ifexp, op1, op2;
  4323. {
  4324.   register tree type1;
  4325.   register tree type2;
  4326.   register enum tree_code code1;
  4327.   register enum tree_code code2;
  4328.   register tree result_type = NULL_TREE;
  4329.  
  4330.   /* If second operand is omitted, it is the same as the first one;
  4331.      make sure it is calculated only once.  */
  4332.   if (op1 == 0)
  4333.     {
  4334.       if (pedantic)
  4335.     pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
  4336.       ifexp = op1 = save_expr (ifexp);
  4337.     }
  4338.  
  4339.   ifexp = truthvalue_conversion (default_conversion (ifexp));
  4340.  
  4341.   if (TREE_CODE (ifexp) == ERROR_MARK)
  4342.     return error_mark_node;
  4343.  
  4344.   op1 = require_instantiated_type (TREE_TYPE (op2), op1, error_mark_node);
  4345.   if (op1 == error_mark_node)
  4346.     return error_mark_node;
  4347.   op2 = require_instantiated_type (TREE_TYPE (op1), op2, error_mark_node);
  4348.   if (op2 == error_mark_node)
  4349.     return error_mark_node;
  4350.  
  4351.   /* C++: REFERENCE_TYPES must be dereferenced.  */
  4352.   type1 = TREE_TYPE (op1);
  4353.   code1 = TREE_CODE (type1);
  4354.   type2 = TREE_TYPE (op2);
  4355.   code2 = TREE_CODE (type2);
  4356.  
  4357.   if (code1 == REFERENCE_TYPE)
  4358.     {
  4359.       op1 = convert_from_reference (op1);
  4360.       type1 = TREE_TYPE (op1);
  4361.       code1 = TREE_CODE (type1);
  4362.     }
  4363.   if (code2 == REFERENCE_TYPE)
  4364.     {
  4365.       op2 = convert_from_reference (op2);
  4366.       type2 = TREE_TYPE (op2);
  4367.       code2 = TREE_CODE (type2);
  4368.     }
  4369.  
  4370. #if 1 /* Produces wrong result if within sizeof.  Sorry.  */
  4371.   /* Don't promote the operands separately if they promote
  4372.      the same way.  Return the unpromoted type and let the combined
  4373.      value get promoted if necessary.  */
  4374.  
  4375.   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2)
  4376.       && code2 != ARRAY_TYPE
  4377. #if 0
  4378.       /* For C++, let the enumeral type come through.  */
  4379.       && code2 != ENUMERAL_TYPE
  4380. #endif
  4381.       && code2 != FUNCTION_TYPE
  4382.       && code2 != METHOD_TYPE)
  4383.     {
  4384.       tree result;
  4385.  
  4386.       if (TREE_CONSTANT (ifexp)
  4387.       && (TREE_CODE (ifexp) == INTEGER_CST
  4388.           || TREE_CODE (ifexp) == ADDR_EXPR))
  4389.     return (integer_zerop (ifexp) ? op2 : op1);
  4390.  
  4391.       if (TREE_CODE (op1) == CONST_DECL)
  4392.     op1 = DECL_INITIAL (op1);
  4393.       else if (TREE_READONLY_DECL_P (op1))
  4394.     op1 = decl_constant_value (op1);
  4395.       if (TREE_CODE (op2) == CONST_DECL)
  4396.     op2 = DECL_INITIAL (op2);
  4397.       else if (TREE_READONLY_DECL_P (op2))
  4398.     op2 = decl_constant_value (op2);
  4399.       if (type1 != type2)
  4400.     type1 = build_type_variant
  4401.             (type1,
  4402.              TREE_READONLY (op1) || TREE_READONLY (op2),
  4403.              TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
  4404.       /* ??? This is a kludge to deal with the fact that
  4405.      we don't sort out integers and enums properly, yet.  */
  4406.       result = fold (build (COND_EXPR, type1, ifexp, op1, op2));
  4407.       if (TREE_TYPE (result) != type1)
  4408.     result = build1 (NOP_EXPR, type1, result);
  4409.       return result;
  4410.     }
  4411. #endif
  4412.  
  4413.   /* They don't match; promote them both and then try to reconcile them.
  4414.      But don't permit mismatching enum types.  */
  4415.   if (code1 == ENUMERAL_TYPE)
  4416.     {
  4417.       if (code2 == ENUMERAL_TYPE)
  4418.     {
  4419.       message_2_types (error, "enumeral mismatch in conditional expression: `%s' vs `%s'", type1, type2);
  4420.       return error_mark_node;
  4421.     }
  4422.       else if (extra_warnings && ! IS_AGGR_TYPE_CODE (code2))
  4423.     warning ("enumeral and non-enumeral type in conditional expression");
  4424.     }
  4425.   else if (extra_warnings
  4426.        && code2 == ENUMERAL_TYPE && ! IS_AGGR_TYPE_CODE (code1))
  4427.     warning ("enumeral and non-enumeral type in conditional expression");
  4428.  
  4429.   if (code1 != VOID_TYPE)
  4430.     {
  4431.       op1 = default_conversion (op1);
  4432.       type1 = TREE_TYPE (op1);
  4433.       code1 = TREE_CODE (type1);
  4434.     }
  4435.   if (code2 != VOID_TYPE)
  4436.     {
  4437.       op2 = default_conversion (op2);
  4438.       type2 = TREE_TYPE (op2);
  4439.       code2 = TREE_CODE (type2);
  4440.     }
  4441.  
  4442.   /* Quickly detect the usual case where op1 and op2 have the same type
  4443.      after promotion.  */
  4444.   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
  4445.     {
  4446.       if (type1 == type2)
  4447.     result_type = type1;
  4448.       else
  4449.     result_type = build_type_variant
  4450.             (type1,
  4451.              TREE_READONLY (op1) || TREE_READONLY (op2),
  4452.              TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
  4453.     }
  4454.   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
  4455.            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
  4456.     {
  4457.       result_type = common_type (type1, type2);
  4458.     }
  4459.   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
  4460.     {
  4461.       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
  4462.     pedwarn ("ANSI C++ forbids conditional expr with only one void side");
  4463.       result_type = void_type_node;
  4464.     }
  4465.   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
  4466.     {
  4467.       if (comp_target_types (type1, type2, 1))
  4468.     result_type = common_type (type1, type2);
  4469.       else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node)
  4470.     result_type = qualify_type (type2, type1);
  4471.       else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node)
  4472.     result_type = qualify_type (type1, type2);
  4473.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
  4474.     {
  4475.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  4476.         pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
  4477.       result_type = qualify_type (type1, type2);
  4478.     }
  4479.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
  4480.     {
  4481.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  4482.         pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
  4483.       result_type = qualify_type (type2, type1);
  4484.     }
  4485.       /* C++ */
  4486.       else if (comptypes (type2, type1, 0))
  4487.     result_type = type2;
  4488.       else if (IS_AGGR_TYPE (TREE_TYPE (type1))
  4489.            && IS_AGGR_TYPE (TREE_TYPE (type2))
  4490.            && (result_type = common_base_type (TREE_TYPE (type1), TREE_TYPE (type2))))
  4491.     {
  4492.       if (result_type == error_mark_node)
  4493.         {
  4494.           message_2_types (error, "common base type of types `%s' and `%s' is ambiguous",
  4495.                    TREE_TYPE (type1), TREE_TYPE (type2));
  4496.           result_type = ptr_type_node;
  4497.         }
  4498.       else result_type = TYPE_POINTER_TO (result_type);
  4499.     }
  4500.       else
  4501.     {
  4502.       pedwarn ("pointer type mismatch in conditional expression");
  4503.       result_type = ptr_type_node;
  4504.     }
  4505.     }
  4506.   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
  4507.     {
  4508.       if (!integer_zerop (op2))
  4509.     warning ("pointer/integer type mismatch in conditional expression");
  4510.       else
  4511.     {
  4512.       op2 = null_pointer_node;
  4513.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  4514.         pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
  4515.     }
  4516.       result_type = type1;
  4517.     }
  4518.   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
  4519.     {
  4520.       if (!integer_zerop (op1))
  4521.     warning ("pointer/integer type mismatch in conditional expression");
  4522.       else
  4523.     {
  4524.       op1 = null_pointer_node;
  4525.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  4526.         pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
  4527.     }
  4528.       result_type = type2;
  4529.       op1 = null_pointer_node;
  4530.     }
  4531.  
  4532.   if (!result_type)
  4533.     {
  4534.       /* The match does not look good.  If either is
  4535.      an aggregate value, try converting to a scalar type.  */
  4536.       if (code1 == RECORD_TYPE && code2 == RECORD_TYPE)
  4537.     {
  4538.       message_2_types (error, "aggregate mismatch in conditional expression: `%s' vs `%s'", type1, type2);
  4539.       return error_mark_node;
  4540.     }
  4541.       if (code1 == RECORD_TYPE && TYPE_HAS_CONVERSION (type1))
  4542.     {
  4543.       tree tmp = build_type_conversion (CONVERT_EXPR, type2, op1, 0);
  4544.       if (tmp == NULL_TREE)
  4545.         {
  4546.           cp_error ("aggregate type `%T' could not convert on lhs of `:'", type1);
  4547.           return error_mark_node;
  4548.         }
  4549.       if (tmp == error_mark_node)
  4550.         error ("ambiguous pointer conversion");
  4551.       result_type = type2;
  4552.       op1 = tmp;
  4553.     }
  4554.       else if (code2 == RECORD_TYPE && TYPE_HAS_CONVERSION (type2))
  4555.     {
  4556.       tree tmp = build_type_conversion (CONVERT_EXPR, type1, op2, 0);
  4557.       if (tmp == NULL_TREE)
  4558.         {
  4559.           cp_error ("aggregate type `%T' could not convert on rhs of `:'", type2);
  4560.           return error_mark_node;
  4561.         }
  4562.       if (tmp == error_mark_node)
  4563.         error ("ambiguous pointer conversion");
  4564.       result_type = type1;
  4565.       op2 = tmp;
  4566.     }
  4567.       else if (flag_cond_mismatch)
  4568.     result_type = void_type_node;
  4569.       else
  4570.     {
  4571.       error ("type mismatch in conditional expression");
  4572.       return error_mark_node;
  4573.     }
  4574.     }
  4575.  
  4576.   if (result_type != TREE_TYPE (op1))
  4577.     op1 = convert_and_check (result_type, op1);
  4578.   if (result_type != TREE_TYPE (op2))
  4579.     op2 = convert_and_check (result_type, op2);
  4580.  
  4581. #if 0
  4582.   /* XXX delete me, I've been here for years.  */
  4583.   if (IS_AGGR_TYPE_CODE (code1))
  4584.     {
  4585.       result_type = TREE_TYPE (op1);
  4586.       if (TREE_CONSTANT (ifexp))
  4587.     return (integer_zerop (ifexp) ? op2 : op1);
  4588.  
  4589.       if (TYPE_MODE (result_type) == BLKmode)
  4590.     {
  4591.       register tree tempvar
  4592.         = build_decl (VAR_DECL, NULL_TREE, result_type);
  4593.       register tree xop1 = build_modify_expr (tempvar, NOP_EXPR, op1);
  4594.       register tree xop2 = build_modify_expr (tempvar, NOP_EXPR, op2);
  4595.       register tree result = fold (build (COND_EXPR, result_type,
  4596.                           ifexp, xop1, xop2));
  4597.  
  4598.       layout_decl (tempvar, 0);
  4599.       /* No way to handle variable-sized objects here.
  4600.          I fear that the entire handling of BLKmode conditional exprs
  4601.          needs to be redone.  */
  4602.       my_friendly_assert (TREE_CONSTANT (DECL_SIZE (tempvar)), 315);
  4603.       DECL_RTL (tempvar)
  4604.         = assign_stack_local (DECL_MODE (tempvar),
  4605.                   (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
  4606.                    + BITS_PER_UNIT - 1)
  4607.                   / BITS_PER_UNIT,
  4608.                   0);
  4609.  
  4610.       TREE_SIDE_EFFECTS (result)
  4611.         = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1)
  4612.           | TREE_SIDE_EFFECTS (op2);
  4613.       return build (COMPOUND_EXPR, result_type, result, tempvar);
  4614.     }
  4615.     }
  4616. #endif /* 0 */
  4617.  
  4618.   if (TREE_CONSTANT (ifexp))
  4619.     return integer_zerop (ifexp) ? op2 : op1;
  4620.  
  4621.   return fold (build (COND_EXPR, result_type, ifexp, op1, op2));
  4622. }
  4623.  
  4624. /* Handle overloading of the ',' operator when needed.  Otherwise,
  4625.    this function just builds an expression list.  */
  4626. tree
  4627. build_x_compound_expr (list)
  4628.      tree list;
  4629. {
  4630.   tree rest = TREE_CHAIN (list);
  4631.   tree result;
  4632.  
  4633.   if (rest == NULL_TREE)
  4634.     return build_compound_expr (list);
  4635.  
  4636.   result = build_opfncall (COMPOUND_EXPR, LOOKUP_NORMAL,
  4637.                TREE_VALUE (list), TREE_VALUE (rest), NULL_TREE);
  4638.   if (result)
  4639.     return build_x_compound_expr (tree_cons (NULL_TREE, result, TREE_CHAIN (rest)));
  4640.   else
  4641.     return build_compound_expr (tree_cons (NULL_TREE, TREE_VALUE (list),
  4642.                        build_tree_list (NULL_TREE, build_x_compound_expr (rest))));
  4643. }
  4644.  
  4645. /* Given a list of expressions, return a compound expression
  4646.    that performs them all and returns the value of the last of them.  */
  4647.  
  4648. tree
  4649. build_compound_expr (list)
  4650.      tree list;
  4651. {
  4652.   register tree rest;
  4653.  
  4654.   if (TREE_READONLY_DECL_P (TREE_VALUE (list)))
  4655.     TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
  4656.  
  4657.   if (TREE_CHAIN (list) == 0)
  4658.     {
  4659.       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  4660.      Strip such NOP_EXPRs, since LIST is used in non-lvalue context.  */
  4661.       if (TREE_CODE (list) == NOP_EXPR
  4662.       && TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0)))
  4663.     list = TREE_OPERAND (list, 0);
  4664.  
  4665.       /* Convert arrays to pointers.  */
  4666.       if (TREE_CODE (TREE_TYPE (TREE_VALUE (list))) == ARRAY_TYPE)
  4667.     return default_conversion (TREE_VALUE (list));
  4668.       else
  4669.     return TREE_VALUE (list);
  4670.     }
  4671.  
  4672.   rest = build_compound_expr (TREE_CHAIN (list));
  4673.  
  4674.   /* When pedantic, a compound expression can be neither an lvalue
  4675.      nor an integer constant expression.  */
  4676.   if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic)
  4677.     return rest;
  4678.  
  4679.   return build (COMPOUND_EXPR, TREE_TYPE (rest),
  4680.         break_out_cleanups (TREE_VALUE (list)), rest);
  4681. }
  4682.  
  4683. /* Build an expression representing a cast to type TYPE of expression EXPR.  */
  4684.  
  4685. tree
  4686. build_c_cast (type, expr)
  4687.      register tree type;
  4688.      tree expr;
  4689. {
  4690.   register tree value = expr;
  4691.  
  4692.   if (type == error_mark_node || expr == error_mark_node)
  4693.     return error_mark_node;
  4694.  
  4695.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  4696.      Strip such NOP_EXPRs, since VALUE is being used in non-lvalue context.  */
  4697.   if (TREE_CODE (value) == NOP_EXPR
  4698.       && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
  4699.     value = TREE_OPERAND (value, 0);
  4700.  
  4701.   if (TREE_TYPE (expr)
  4702.       && TREE_CODE (TREE_TYPE (expr)) == OFFSET_TYPE
  4703.       && TREE_CODE (type) != OFFSET_TYPE)
  4704.     value = resolve_offset_ref (value);
  4705.  
  4706.   if (TREE_CODE (type) == ARRAY_TYPE)
  4707.     {
  4708.       /* Allow casting from T1* to T2[] because Cfront allows it.
  4709.      NIHCL uses it. It is not valid ANSI C however, and hence, not
  4710.      valid ANSI C++.  */
  4711.       if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)
  4712.     {
  4713.       if (pedantic)
  4714.         pedwarn ("ANSI C++ forbids casting to an array type");
  4715.       type = build_pointer_type (TREE_TYPE (type));
  4716.     }
  4717.       else
  4718.     {
  4719.       error ("ANSI C++ forbids casting to an array type");
  4720.       return error_mark_node;
  4721.     }
  4722.     }
  4723.  
  4724.   /* When converting into a reference type, just convert into a pointer to
  4725.      the new type and deference it.  While this is not exactly what ARM 5.4
  4726.      calls for [why not? -jason], it is pretty close for now.
  4727.      (int &)ri ---> *(int*)&ri  */
  4728.   if (TREE_CODE (type) == REFERENCE_TYPE)
  4729.     {
  4730.       value = build_unary_op (ADDR_EXPR, value, 0);
  4731.       if (value != error_mark_node)
  4732.     value = convert (build_pointer_type (TREE_TYPE (type)), value);
  4733.       if (value != error_mark_node)
  4734.     value = build_indirect_ref (value, "reference conversion");
  4735.       return value;
  4736.     }
  4737.  
  4738.   if (TREE_TYPE (value)
  4739.       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
  4740.     {
  4741.       /* For C++, we must copy the constness of TYPE into VALUE.  */
  4742.       if (TREE_READONLY (value) != TYPE_READONLY (type))
  4743.     {
  4744.       value = copy_node (value);
  4745.       TREE_READONLY (value) = TYPE_READONLY (type);
  4746.     }
  4747.       else if (pedantic)
  4748.     {
  4749.       if (TREE_CODE (type) == RECORD_TYPE
  4750.           || TREE_CODE (type) == UNION_TYPE)
  4751.         pedwarn ("ANSI C++ forbids casting nonscalar to the same type");
  4752.     }
  4753.       return value;
  4754.     }
  4755.  
  4756.   /* If there's only one function in the overloaded space,
  4757.      just take it.  */
  4758.   if (TREE_CODE (value) == TREE_LIST
  4759.       && TREE_CHAIN (value) == NULL_TREE)
  4760.     value = TREE_VALUE (value);
  4761.  
  4762.   /* Make up for the fact that we do not always perform
  4763.      `default_conversion' anymore.  */
  4764.   if (TREE_READONLY_DECL_P (value))
  4765.     value = decl_constant_value (value);
  4766.  
  4767.   if (TREE_TYPE (value) == NULL_TREE
  4768.       || type_unknown_p (value))
  4769.     {
  4770.       value = instantiate_type (type, value, 1);
  4771.       /* Did we lose?  */
  4772.       if (value == error_mark_node)
  4773.     return error_mark_node;
  4774.     }
  4775.   else
  4776.     {
  4777.       tree otype, ovalue;
  4778.  
  4779.       /* Convert functions and arrays to pointers and
  4780.      convert references to their expanded types,
  4781.      but don't convert any other types.  */
  4782.       if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
  4783.       || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
  4784.       || TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
  4785.     value = default_conversion (value);
  4786.       otype = TREE_TYPE (value);
  4787.  
  4788.       /* Optionally warn about potentially worrisome casts.  */
  4789.  
  4790.       if (warn_cast_qual
  4791.       && TREE_CODE (type) == POINTER_TYPE
  4792.       && TREE_CODE (otype) == POINTER_TYPE)
  4793.     {
  4794.       /* For C++ we make these regular warnings, rather than
  4795.          softening them into pedwarns.  */
  4796.       if (TYPE_VOLATILE (TREE_TYPE (otype))
  4797.           && ! TYPE_VOLATILE (TREE_TYPE (type)))
  4798.         warning ("cast discards `volatile' from pointer target type");
  4799.       if (TYPE_READONLY (TREE_TYPE (otype))
  4800.           && ! TYPE_READONLY (TREE_TYPE (type)))
  4801.         warning ("cast discards `const' from pointer target type");
  4802.     }
  4803.  
  4804.       /* Warn about possible alignment problems.  */
  4805.       if (STRICT_ALIGNMENT && warn_cast_align
  4806.       && TREE_CODE (type) == POINTER_TYPE
  4807.       && TREE_CODE (otype) == POINTER_TYPE
  4808.       && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
  4809.       && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
  4810.       && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
  4811.     warning ("cast increases required alignment of target type");
  4812.  
  4813. #if 0
  4814.       if (TREE_CODE (type) == INTEGER_TYPE
  4815.       && TREE_CODE (otype) == POINTER_TYPE
  4816.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
  4817.     warning ("cast from pointer to integer of different size");
  4818.  
  4819.       if (TREE_CODE (type) == POINTER_TYPE
  4820.       && TREE_CODE (otype) == INTEGER_TYPE
  4821.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
  4822.       /* Don't warn about converting 0 to pointer,
  4823.          provided the 0 was explicit--not cast or made by folding.  */
  4824.       && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value)))
  4825.     warning ("cast to pointer from integer of different size");
  4826. #endif
  4827.  
  4828.       ovalue = value;
  4829.       value = convert_force (type, value);
  4830.  
  4831.       /* Ignore any integer overflow caused by the cast.  */
  4832.       if (TREE_CODE (value) == INTEGER_CST)
  4833.     {
  4834.       TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
  4835.       TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
  4836.     }
  4837.     }
  4838.   if (value == expr)
  4839.     /* Always produce some operator for an explicit cast,
  4840.        so we can tell (for -pedantic) that the cast is no lvalue.  */
  4841.     {
  4842.       tree nvalue = build1 (NOP_EXPR, type, value);
  4843.       TREE_CONSTANT (nvalue) = TREE_CONSTANT (value);
  4844.       return nvalue;
  4845.     }
  4846.  
  4847.   return value;
  4848. }
  4849.  
  4850. /* Build an assignment expression of lvalue LHS from value RHS.
  4851.  
  4852.    In C++, if the left hand side of the assignment is a REFERENCE_TYPE,
  4853.    that reference becomes deferenced down to it base type. */
  4854.  
  4855. /* Return a reference to the BASE_INDEX part of EXPR.  TYPE is
  4856.    the type to which BASE_INDEX applies.  */
  4857. static tree
  4858. get_base_ref (type, base_index, expr)
  4859.      tree type;
  4860.      int base_index;
  4861.      tree expr;
  4862. {
  4863.   tree binfos = TYPE_BINFO_BASETYPES (type);
  4864.   tree base_binfo = TREE_VEC_ELT (binfos, base_index);
  4865.   tree ref;
  4866.  
  4867.   if (TREE_CODE (expr) == ARRAY_REF
  4868.       || ! BINFO_OFFSET_ZEROP (base_binfo)
  4869.       || TREE_VIA_VIRTUAL (base_binfo)
  4870.       || TYPE_MODE (type) != TYPE_MODE (BINFO_TYPE (base_binfo)))
  4871.     {
  4872.       tree addr = build_unary_op (ADDR_EXPR, expr, 0);
  4873.       ref = build_indirect_ref (convert_pointer_to (base_binfo, addr),
  4874.                 NULL_PTR);
  4875.     }
  4876.   else
  4877.     {
  4878.       ref = copy_node (expr);
  4879.       TREE_TYPE (ref) = BINFO_TYPE (base_binfo);
  4880.     }
  4881.   return ref;
  4882. }
  4883.  
  4884. /* Build an assignment expression of lvalue LHS from value RHS.
  4885.    MODIFYCODE is the code for a binary operator that we use
  4886.    to combine the old value of LHS with RHS to get the new value.
  4887.    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
  4888.  
  4889.    C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
  4890.  
  4891.    `build_modify_expr_1' implements recursive part of memberwise
  4892.    assignment operation.  */
  4893. static tree
  4894. build_modify_expr_1 (lhs, modifycode, rhs, basetype_path)
  4895.      tree lhs, rhs;
  4896.      enum tree_code modifycode;
  4897.      tree basetype_path;
  4898. {
  4899.   register tree result;
  4900.   tree newrhs = rhs;
  4901.   tree lhstype = TREE_TYPE (lhs);
  4902.   tree olhstype = lhstype;
  4903.  
  4904.   /* Avoid duplicate error messages from operands that had errors.  */
  4905.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  4906.     return error_mark_node;
  4907.  
  4908.   /* If a binary op has been requested, combine the old LHS value with the RHS
  4909.      producing the value we should actually store into the LHS.  */
  4910.  
  4911.   if (modifycode == INIT_EXPR)
  4912.     ;
  4913.   else if (modifycode == NOP_EXPR)
  4914.     {
  4915.       /* must deal with overloading of `operator=' here.  */
  4916.       if (TREE_CODE (lhstype) == REFERENCE_TYPE)
  4917.     lhstype = TREE_TYPE (lhstype);
  4918.       else
  4919.     lhstype = olhstype;
  4920.     }
  4921.   else
  4922.     {
  4923.       lhs = stabilize_reference (lhs);
  4924.       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
  4925.       modifycode = NOP_EXPR;
  4926.     }
  4927.  
  4928.   /* If storing into a structure or union member,
  4929.      it has probably been given type `int'.
  4930.      Compute the type that would go with
  4931.      the actual amount of storage the member occupies.  */
  4932.  
  4933.   if (TREE_CODE (lhs) == COMPONENT_REF
  4934.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  4935.       || TREE_CODE (lhstype) == REAL_TYPE
  4936.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  4937.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  4938.  
  4939.   /* C++: The semantics of C++ differ from those of C when an
  4940.      assignment of an aggregate is desired.  Assignment in C++ is
  4941.      now defined as memberwise assignment of non-static members
  4942.      and base class objects.  This rule applies recursively
  4943.      until a member of a built-in type is found.
  4944.  
  4945.      Also, we cannot do a bit-wise copy of aggregates which
  4946.      contain virtual function table pointers.  Those
  4947.      pointer values must be preserved through the copy.
  4948.      However, this is handled in expand_expr, and not here.
  4949.      This is because much better code can be generated at
  4950.      that stage than this one.  */
  4951.   if (TREE_CODE (lhstype) == RECORD_TYPE
  4952.       && TYPE_LANG_SPECIFIC (lhstype)
  4953.       && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs)))
  4954.     {
  4955.       register tree elt;
  4956.       int i;
  4957.  
  4958.       /* Perform operation on object.  */
  4959.       if (modifycode == INIT_EXPR && TYPE_HAS_INIT_REF (lhstype))
  4960.     {
  4961.       result = build_method_call (lhs, constructor_name_full (lhstype),
  4962.                       build_tree_list (NULL_TREE, rhs),
  4963.                       basetype_path, LOOKUP_NORMAL);
  4964.       return build_indirect_ref (result, NULL_PTR);
  4965.     }
  4966.       else if (modifycode == NOP_EXPR)
  4967.     {
  4968.       /* `operator=' is not an inheritable operator; see 13.4.3.  */
  4969.       if (TYPE_LANG_SPECIFIC (lhstype) && TYPE_HAS_ASSIGNMENT (lhstype))
  4970.         {
  4971.           result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
  4972.                        lhs, rhs, make_node (NOP_EXPR));
  4973.           if (result == NULL_TREE)
  4974.         return error_mark_node;
  4975.           return result;
  4976.         }
  4977.     }
  4978.  
  4979.       if (TYPE_USES_VIRTUAL_BASECLASSES (lhstype)
  4980.       || (modifycode == NOP_EXPR && TYPE_GETS_ASSIGNMENT (lhstype))
  4981.       || (modifycode == INIT_EXPR && TYPE_GETS_INIT_REF (lhstype)))
  4982.     {
  4983.       tree binfos = BINFO_BASETYPES (TYPE_BINFO (lhstype));
  4984.       result = NULL_TREE;
  4985.  
  4986.       if (binfos != NULL_TREE)
  4987.         /* Perform operation on each member, depth-first, left-right.  */
  4988.         for (i = 0; i <= TREE_VEC_LENGTH (binfos)-1; i++)
  4989.           {
  4990.         tree base_binfo = TREE_VEC_ELT (binfos, i);
  4991.         tree base_lhs, base_rhs;
  4992.         tree new_result;
  4993.  
  4994.         /* Assignments from virtual baseclasses handled elsewhere.  */
  4995.         if (TREE_VIA_VIRTUAL (base_binfo))
  4996.           continue;
  4997.  
  4998.         base_lhs = get_base_ref (lhstype, i, lhs);
  4999.         base_rhs = get_base_ref (lhstype, i, newrhs);
  5000.  
  5001.         BINFO_INHERITANCE_CHAIN (base_binfo) = basetype_path;
  5002.         new_result
  5003.           = build_modify_expr_1 (base_lhs, modifycode, base_rhs,
  5004.                      base_binfo);
  5005.  
  5006.         /* We either get back a compound stmt, or a simple one.  */
  5007.         if (new_result && TREE_CODE (new_result) == TREE_LIST)
  5008.           new_result = build_compound_expr (new_result);
  5009.         result = tree_cons (NULL_TREE, new_result, result);
  5010.           }
  5011.  
  5012.       for (elt = TYPE_FIELDS (lhstype); elt; elt = TREE_CHAIN (elt))
  5013.         {
  5014.           tree vbases = NULL_TREE;
  5015.           tree elt_lhs, elt_rhs;
  5016.  
  5017.           if (TREE_CODE (elt) != FIELD_DECL)
  5018.         continue;
  5019.           if (DECL_NAME (elt)
  5020.           && (VFIELD_NAME_P (DECL_NAME (elt))
  5021.               || VBASE_NAME_P (DECL_NAME (elt))))
  5022.         continue;
  5023.  
  5024.           if (TREE_READONLY (elt)
  5025.           || TREE_CODE (TREE_TYPE (elt)) == REFERENCE_TYPE)
  5026.         {
  5027.           cp_error ("cannot generate default `%T::operator ='",
  5028.                 lhstype);
  5029.           if (TREE_CODE (TREE_TYPE (elt)) == REFERENCE_TYPE)
  5030.             cp_error_at ("because member `%#D' is a reference", elt);
  5031.           else
  5032.             cp_error_at ("because member `%#D' is const", elt);
  5033.  
  5034.           return error_mark_node;
  5035.         }
  5036.  
  5037.           if (IS_AGGR_TYPE (TREE_TYPE (elt))
  5038.           && TYPE_LANG_SPECIFIC (TREE_TYPE (elt)))
  5039.         vbases = CLASSTYPE_VBASECLASSES (TREE_TYPE (elt));
  5040.  
  5041.           elt_lhs = build (COMPONENT_REF, TREE_TYPE (elt), lhs, elt);
  5042.           elt_rhs = build (COMPONENT_REF, TREE_TYPE (elt), newrhs, elt);
  5043.           /* It is not always safe to go through `build_modify_expr_1'
  5044.          when performing element-wise copying.  This is because
  5045.          an element may be of ARRAY_TYPE, which will not
  5046.          be properly copied as a naked element.  */
  5047.           if (TREE_CODE (TREE_TYPE (elt)) == RECORD_TYPE
  5048.           && TYPE_LANG_SPECIFIC (TREE_TYPE (elt)))
  5049.         basetype_path = TYPE_BINFO (TREE_TYPE (elt));
  5050.  
  5051.           while (vbases)
  5052.         {
  5053.           tree elt_lhs_addr = build_unary_op (ADDR_EXPR, elt_lhs, 0);
  5054.           tree elt_rhs_addr = build_unary_op (ADDR_EXPR, elt_rhs, 0);
  5055.  
  5056.           elt_lhs_addr = convert_pointer_to (vbases, elt_lhs_addr);
  5057.           elt_rhs_addr = convert_pointer_to (vbases, elt_rhs_addr);
  5058.           result
  5059.             = tree_cons (NULL_TREE,
  5060.                  build_modify_expr_1
  5061.                  (build_indirect_ref (elt_lhs_addr, NULL_PTR),
  5062.                   modifycode,
  5063.                   build_indirect_ref (elt_rhs_addr, NULL_PTR),
  5064.                   basetype_path),
  5065.                  result);
  5066.           if (TREE_VALUE (result) == error_mark_node)
  5067.             return error_mark_node;
  5068.           vbases = TREE_CHAIN (vbases);
  5069.         }
  5070.           elt_lhs = build_modify_expr_1 (elt_lhs, modifycode, elt_rhs,
  5071.                          basetype_path);
  5072.           result = tree_cons (NULL_TREE, elt_lhs, result);
  5073.         }
  5074.  
  5075.       if (result)
  5076.         return build_compound_expr (result);
  5077.       /* No fields to move.  */
  5078.       return integer_zero_node;
  5079.     }
  5080.       else
  5081.     {
  5082.       result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
  5083.               void_type_node, lhs, rhs);
  5084.       TREE_SIDE_EFFECTS (result) = 1;
  5085.       return result;
  5086.     }
  5087.     }
  5088.  
  5089.   result = build_modify_expr (lhs, modifycode, newrhs);
  5090.   /* ARRAY_TYPEs cannot be converted to anything meaningful,
  5091.      and leaving it there screws up `build_compound_expr' when
  5092.      it tries to defaultly convert everything.  */
  5093.   if (TREE_CODE (TREE_TYPE (result)) == ARRAY_TYPE)
  5094.     TREE_TYPE (result) = void_type_node;
  5095.   return result;
  5096. }
  5097.  
  5098. /* Taken from expr.c:
  5099.    Subroutine of expand_expr:
  5100.    record the non-copied parts (LIST) of an expr (LHS), and return a list
  5101.    which specifies the initial values of these parts.  */
  5102.  
  5103. static tree
  5104. init_noncopied_parts (lhs, list)
  5105.      tree lhs;
  5106.      tree list;
  5107. {
  5108.   tree tail;
  5109.   tree parts = 0;
  5110.  
  5111.   for (tail = list; tail; tail = TREE_CHAIN (tail))
  5112.     if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
  5113.       parts = chainon (parts, init_noncopied_parts (lhs, TREE_VALUE (tail)));
  5114.     else
  5115.       {
  5116.     tree part = TREE_VALUE (tail);
  5117.     tree part_type = TREE_TYPE (part);
  5118.     tree to_be_initialized = build (COMPONENT_REF, part_type, lhs, part);
  5119.     parts = tree_cons (TREE_PURPOSE (tail), to_be_initialized, parts);
  5120.       }
  5121.   return parts;
  5122. }
  5123.  
  5124. tree
  5125. build_modify_expr (lhs, modifycode, rhs)
  5126.      tree lhs;
  5127.      enum tree_code modifycode;
  5128.      tree rhs;
  5129. {
  5130.   register tree result;
  5131.   tree newrhs = rhs;
  5132.   tree lhstype = TREE_TYPE (lhs);
  5133.   tree olhstype = lhstype;
  5134.  
  5135.   /* Types that aren't fully specified cannot be used in assignments.  */
  5136.   lhs = require_complete_type (lhs);
  5137.  
  5138.   /* Avoid duplicate error messages from operands that had errors.  */
  5139.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  5140.     return error_mark_node;
  5141.  
  5142.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  5143.      Strip such NOP_EXPRs, since RHS is being used in non-lvalue context.  */
  5144.   if (TREE_CODE (rhs) == NOP_EXPR
  5145.       && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0)))
  5146.     rhs = TREE_OPERAND (rhs, 0);
  5147.  
  5148.   /* Decide early if we are going to protect RHS from GC
  5149.      before assigning it to LHS.  */
  5150.   if (type_needs_gc_entry (TREE_TYPE (rhs))
  5151.       && ! value_safe_from_gc (lhs, rhs))
  5152.     rhs = protect_value_from_gc (lhs, rhs);
  5153.  
  5154.   newrhs = rhs;
  5155.  
  5156.   /* Handle control structure constructs used as "lvalues".  */
  5157.  
  5158.   switch (TREE_CODE (lhs))
  5159.     {
  5160.       /* Handle --foo = 5; as these are valid constructs in C++ */
  5161.     case PREDECREMENT_EXPR:
  5162.     case PREINCREMENT_EXPR:
  5163.       if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
  5164.     lhs = build (TREE_CODE (lhs), TREE_TYPE (lhs),
  5165.              stabilize_reference (TREE_OPERAND (lhs, 0)));
  5166.       return build (COMPOUND_EXPR, lhstype,
  5167.             lhs,
  5168.             build_modify_expr (TREE_OPERAND (lhs, 0),
  5169.                        modifycode, rhs));
  5170.  
  5171.       /* Handle (a, b) used as an "lvalue".  */
  5172.     case COMPOUND_EXPR:
  5173.       pedantic_lvalue_warning (COMPOUND_EXPR);
  5174.       newrhs = build_modify_expr (TREE_OPERAND (lhs, 1),
  5175.                   modifycode, rhs);
  5176.       if (TREE_CODE (newrhs) == ERROR_MARK)
  5177.     return error_mark_node;
  5178.       return build (COMPOUND_EXPR, lhstype,
  5179.             TREE_OPERAND (lhs, 0), newrhs);
  5180.  
  5181.       /* Handle (a ? b : c) used as an "lvalue".  */
  5182.     case COND_EXPR:
  5183.       pedantic_lvalue_warning (COND_EXPR);
  5184.       rhs = save_expr (rhs);
  5185.       {
  5186.     /* Produce (a ? (b = rhs) : (c = rhs))
  5187.        except that the RHS goes through a save-expr
  5188.        so the code to compute it is only emitted once.  */
  5189.     tree cond
  5190.       = build_conditional_expr (TREE_OPERAND (lhs, 0),
  5191.                     build_modify_expr (TREE_OPERAND (lhs, 1),
  5192.                                modifycode, rhs),
  5193.                     build_modify_expr (TREE_OPERAND (lhs, 2),
  5194.                                modifycode, rhs));
  5195.     if (TREE_CODE (cond) == ERROR_MARK)
  5196.       return cond;
  5197.     /* Make sure the code to compute the rhs comes out
  5198.        before the split.  */
  5199.     return build (COMPOUND_EXPR, TREE_TYPE (lhs),
  5200.               /* Case to void to suppress warning
  5201.              from warn_if_unused_value.  */
  5202.               convert (void_type_node, rhs), cond);
  5203.       }
  5204.     }
  5205.  
  5206.   /* If a binary op has been requested, combine the old LHS value with the RHS
  5207.      producing the value we should actually store into the LHS.  */
  5208.  
  5209.   if (modifycode == INIT_EXPR)
  5210.     ;
  5211.   else if (modifycode == NOP_EXPR)
  5212.     {
  5213.       /* must deal with overloading of `operator=' here.  */
  5214.       if (TREE_CODE (lhstype) == REFERENCE_TYPE)
  5215.     lhstype = TREE_TYPE (lhstype);
  5216. #if 1
  5217.       /* `operator=' is not an inheritable operator.  */
  5218.       if (TYPE_LANG_SPECIFIC (lhstype) && TYPE_HAS_ASSIGNMENT (lhstype))
  5219.     {
  5220.       result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
  5221.                    lhs, rhs, make_node (NOP_EXPR));
  5222.       if (result == NULL_TREE)
  5223.         return error_mark_node;
  5224.       return result;
  5225.     }
  5226. #else
  5227.       /* Treat `operator=' as an inheritable operator.  */
  5228.       if (TYPE_LANG_SPECIFIC (lhstype) && TYPE_GETS_ASSIGNMENT (lhstype))
  5229.     {
  5230.       tree orig_lhstype = lhstype;
  5231.       while (! TYPE_HAS_ASSIGNMENT (lhstype))
  5232.         {
  5233.           int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (lhstype);
  5234.           tree basetype = NULL_TREE;
  5235.           for (i = 0; i < n_baseclasses; i++)
  5236.         if (TYPE_GETS_ASSIGNMENT (TYPE_BINFO_BASETYPE (lhstype, i)))
  5237.           {
  5238.             if (basetype != NULL_TREE)
  5239.               {
  5240.             message_2_types (error, "base classes `%s' and `%s' both have operator ='",
  5241.                      basetype,
  5242.                      TYPE_BINFO_BASETYPE (lhstype, i));
  5243.             return error_mark_node;
  5244.               }
  5245.             basetype = TYPE_BINFO_BASETYPE (lhstype, i);
  5246.           }
  5247.           lhstype = basetype;
  5248.         }
  5249.       if (orig_lhstype != lhstype)
  5250.         {
  5251.           lhs = build_indirect_ref (convert_pointer_to (lhstype,
  5252.                                 build_unary_op (ADDR_EXPR, lhs, 0)), NULL_PTR);
  5253.           if (lhs == error_mark_node)
  5254.         {
  5255.           cp_error ("conversion to private basetype `%T'", lhstype);
  5256.           return error_mark_node;
  5257.         }
  5258.         }
  5259.       result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
  5260.                    lhs, rhs, make_node (NOP_EXPR));
  5261.       if (result == NULL_TREE)
  5262.         return error_mark_node;
  5263.       return result;
  5264.     }
  5265. #endif
  5266.       lhstype = olhstype;
  5267.     }
  5268.   else if (PROMOTES_TO_AGGR_TYPE (lhstype, REFERENCE_TYPE))
  5269.     {
  5270.       /* This case must convert to some sort of lvalue that
  5271.      can participate in an op= operation.  */
  5272.       tree lhs_tmp = lhs;
  5273.       tree rhs_tmp = rhs;
  5274.       if (build_default_binary_type_conversion (modifycode, &lhs_tmp, &rhs_tmp))
  5275.     {
  5276.       lhs = stabilize_reference (lhs_tmp);
  5277.       /* Forget is was ever anything else.  */
  5278.       olhstype = lhstype = TREE_TYPE (lhs);
  5279.       newrhs = build_binary_op (modifycode, lhs, rhs_tmp, 1);
  5280.     }
  5281.       else
  5282.     return error_mark_node;
  5283.     }
  5284.   else
  5285.     {
  5286.       lhs = stabilize_reference (lhs);
  5287.       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
  5288.     }
  5289.  
  5290.   /* Handle a cast used as an "lvalue".
  5291.      We have already performed any binary operator using the value as cast.
  5292.      Now convert the result to the cast type of the lhs,
  5293.      and then true type of the lhs and store it there;
  5294.      then convert result back to the cast type to be the value
  5295.      of the assignment.  */
  5296.  
  5297.   switch (TREE_CODE (lhs))
  5298.     {
  5299.     case NOP_EXPR:
  5300.     case CONVERT_EXPR:
  5301.     case FLOAT_EXPR:
  5302.     case FIX_TRUNC_EXPR:
  5303.     case FIX_FLOOR_EXPR:
  5304.     case FIX_ROUND_EXPR:
  5305.     case FIX_CEIL_EXPR:
  5306.       if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
  5307.       || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE
  5308.       || TREE_CODE (TREE_TYPE (newrhs)) == METHOD_TYPE
  5309.       || TREE_CODE (TREE_TYPE (newrhs)) == OFFSET_TYPE)
  5310.     newrhs = default_conversion (newrhs);
  5311.       {
  5312.     tree inner_lhs = TREE_OPERAND (lhs, 0);
  5313.     tree result;
  5314.     result = build_modify_expr (inner_lhs, NOP_EXPR,
  5315.                     convert (TREE_TYPE (inner_lhs),
  5316.                          convert (lhstype, newrhs)));
  5317.     if (TREE_CODE (result) == ERROR_MARK)
  5318.       return result;
  5319.     return convert (TREE_TYPE (lhs), result);
  5320.       }
  5321.     }
  5322.  
  5323.   if (TREE_CODE (lhs) == OFFSET_REF)
  5324.     {
  5325.       if (TREE_OPERAND (lhs, 0) == NULL_TREE)
  5326.     {
  5327.       /* Static class member?  */
  5328.       tree member = TREE_OPERAND (lhs, 1);
  5329.       if (TREE_CODE (member) == VAR_DECL)
  5330.         lhs = member;
  5331.       else
  5332.         {
  5333.           compiler_error ("invalid static class member");
  5334.           return error_mark_node;
  5335.         }
  5336.     }
  5337.       else
  5338.     lhs = resolve_offset_ref (lhs);
  5339.     }
  5340.  
  5341.   /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
  5342.      Reject anything strange now.  */
  5343.  
  5344.   if (!lvalue_or_else (lhs, "assignment"))
  5345.     return error_mark_node;
  5346.  
  5347.   GNU_xref_assign (lhs);
  5348.  
  5349.   /* Warn about storing in something that is `const'.  */
  5350.   /* For C++, don't warn if this is initialization.  */
  5351.   if (modifycode != INIT_EXPR
  5352.       && (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
  5353.       || ((TREE_CODE (lhstype) == RECORD_TYPE
  5354.            || TREE_CODE (lhstype) == UNION_TYPE)
  5355.           && C_TYPE_FIELDS_READONLY (lhstype))
  5356.       || (TREE_CODE (lhstype) == REFERENCE_TYPE
  5357.           && TYPE_READONLY (TREE_TYPE (lhstype)))))
  5358.     readonly_error (lhs, "assignment", 0);
  5359.  
  5360.   /* If storing into a structure or union member,
  5361.      it has probably been given type `int'.
  5362.      Compute the type that would go with
  5363.      the actual amount of storage the member occupies.  */
  5364.  
  5365.   if (TREE_CODE (lhs) == COMPONENT_REF
  5366.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  5367.       || TREE_CODE (lhstype) == REAL_TYPE
  5368.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  5369.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  5370.  
  5371.   /* check to see if there is an assignment to `this' */
  5372.   if (lhs == current_class_decl)
  5373.     {
  5374.       if (flag_this_is_variable > 0
  5375.       && DECL_NAME (current_function_decl) != NULL_TREE
  5376.       && current_class_name != DECL_NAME (current_function_decl))
  5377.     warning ("assignment to `this' not in constructor or destructor");
  5378.       current_function_just_assigned_this = 1;
  5379.     }
  5380.  
  5381.   /* The TREE_TYPE of RHS may be TYPE_UNKNOWN.  This can happen
  5382.      when the type of RHS is not yet known, i.e. its type
  5383.      is inherited from LHS.  */
  5384.   rhs = require_instantiated_type (lhstype, newrhs, error_mark_node);
  5385.   if (rhs == error_mark_node)
  5386.     return error_mark_node;
  5387.   newrhs = rhs;
  5388.  
  5389.   if (modifycode != INIT_EXPR)
  5390.     {
  5391.       /* Make modifycode now either a NOP_EXPR or an INIT_EXPR.  */
  5392.       modifycode = NOP_EXPR;
  5393.       /* Reference-bashing */
  5394.       if (TREE_CODE (lhstype) == REFERENCE_TYPE)
  5395.     {
  5396.       tree tmp = convert_from_reference (lhs);
  5397.       lhstype = TREE_TYPE (tmp);
  5398.       if (TYPE_SIZE (lhstype) == 0)
  5399.         {
  5400.           incomplete_type_error (lhs, lhstype);
  5401.           return error_mark_node;
  5402.         }
  5403.       lhs = tmp;
  5404.       olhstype = lhstype;
  5405.     }
  5406.       if (TREE_CODE (TREE_TYPE (newrhs)) == REFERENCE_TYPE)
  5407.     {
  5408.       tree tmp = convert_from_reference (newrhs);
  5409.       if (TYPE_SIZE (TREE_TYPE (tmp)) == 0)
  5410.         {
  5411.           incomplete_type_error (newrhs, TREE_TYPE (tmp));
  5412.           return error_mark_node;
  5413.         }
  5414.       newrhs = tmp;
  5415.     }
  5416.     }
  5417.  
  5418.   if (TREE_SIDE_EFFECTS (lhs))
  5419.     lhs = stabilize_reference (lhs);
  5420.   if (TREE_SIDE_EFFECTS (newrhs))
  5421.     newrhs = stabilize_reference (newrhs);
  5422.  
  5423.   /* C++: The semantics of C++ differ from those of C when an
  5424.      assignment of an aggregate is desired.  Assignment in C++ is
  5425.      now defined as memberwise assignment of non-static members
  5426.      and base class objects.  This rule applies recursively
  5427.      until a member of a built-in type is found.
  5428.  
  5429.      Also, we cannot do a bit-wise copy of aggregates which
  5430.      contain virtual function table pointers.  Those
  5431.      pointer values must be preserved through the copy.
  5432.      However, this is handled in expand_expr, and not here.
  5433.      This is because much better code can be generated at
  5434.      that stage than this one.  */
  5435.   if (TREE_CODE (lhstype) == RECORD_TYPE
  5436.       && (TYPE_USES_VIRTUAL_BASECLASSES (lhstype)
  5437.       || (modifycode != INIT_EXPR && TYPE_GETS_ASSIGNMENT (lhstype))
  5438.       || (modifycode == INIT_EXPR && TYPE_GETS_INIT_REF (lhstype)))
  5439.       && (TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs))
  5440.       || (TREE_CODE (TREE_TYPE (newrhs)) == RECORD_TYPE
  5441.           && UNIQUELY_DERIVED_FROM_P (lhstype, TREE_TYPE (newrhs)))))
  5442.     {
  5443.       tree vbases = CLASSTYPE_VBASECLASSES (lhstype);
  5444.       tree lhs_addr = build_unary_op (ADDR_EXPR, lhs, 0);
  5445.       tree rhs_addr;
  5446.  
  5447.       /* Memberwise assignment would cause NEWRHS to be
  5448.      evaluated for every member that gets assigned.
  5449.      By wrapping side-effecting exprs in a SAVE_EXPR,
  5450.      NEWRHS will only be evaluated once.  */
  5451.       if (IS_AGGR_TYPE (TREE_TYPE (newrhs))
  5452.       && TREE_SIDE_EFFECTS (newrhs)
  5453.       /* This are things we don't have to save.  */
  5454.       && TREE_CODE (newrhs) != TARGET_EXPR
  5455.       && TREE_CODE (newrhs) != WITH_CLEANUP_EXPR)
  5456.     /* Call `break_out_cleanups' on NEWRHS in case there are cleanups.
  5457.        If NEWRHS is a CALL_EXPR that needs a cleanup, failure to do so
  5458.        will result in expand_expr expanding the call without knowing
  5459.        that it should run the cleanup.  */
  5460.     newrhs = save_expr (break_out_cleanups (newrhs));
  5461.  
  5462.       rhs_addr = build_unary_op (ADDR_EXPR, newrhs, 0);
  5463.       result = tree_cons (NULL_TREE,
  5464.               convert (build_reference_type (lhstype), lhs),
  5465.               NULL_TREE);
  5466.  
  5467.       if (! comptypes (TREE_TYPE (lhs_addr), TREE_TYPE (rhs_addr), 1))
  5468.     rhs_addr = convert_pointer_to (TREE_TYPE (TREE_TYPE (lhs_addr)), rhs_addr);
  5469.       {
  5470.     tree noncopied_parts = NULL_TREE;
  5471.  
  5472.     if (TYPE_NONCOPIED_PARTS (lhstype) != 0)
  5473.       noncopied_parts = init_noncopied_parts (lhs,
  5474.                           TYPE_NONCOPIED_PARTS (lhstype));
  5475.     while (noncopied_parts != 0)
  5476.       {
  5477.         result = tree_cons (NULL_TREE,
  5478.                 build_modify_expr (convert (ptr_type_node, TREE_VALUE (noncopied_parts)),
  5479.                            NOP_EXPR,
  5480.                            TREE_PURPOSE (noncopied_parts)),
  5481.                 result);
  5482.         noncopied_parts = TREE_CHAIN (noncopied_parts);
  5483.       }
  5484.       }
  5485.       /* Once we have our hands on an address, we must change NEWRHS
  5486.      to work from there.  Otherwise we can get multiple evaluations
  5487.      of NEWRHS.  */
  5488.       if (TREE_CODE (newrhs) != SAVE_EXPR)
  5489.     newrhs = build_indirect_ref (rhs_addr, NULL_PTR);
  5490.  
  5491.       while (vbases)
  5492.     {
  5493.       tree elt_lhs = convert_pointer_to (vbases, lhs_addr);
  5494.       tree elt_rhs = convert_pointer_to (vbases, rhs_addr);
  5495.       result
  5496.         = tree_cons (NULL_TREE,
  5497.              build_modify_expr_1 (build_indirect_ref (elt_lhs, NULL_PTR),
  5498.                           modifycode,
  5499.                           build_indirect_ref (elt_rhs, NULL_PTR),
  5500.                           TYPE_BINFO (lhstype)),
  5501.              result);
  5502.       if (TREE_VALUE (result) == error_mark_node)
  5503.         return error_mark_node;
  5504.       vbases = TREE_CHAIN (vbases);
  5505.     }
  5506.       result = tree_cons (NULL_TREE,
  5507.               build_modify_expr_1 (lhs,
  5508.                            modifycode,
  5509.                            newrhs,
  5510.                            TYPE_BINFO (lhstype)),
  5511.               result);
  5512.       return build_compound_expr (result);
  5513.     }
  5514.  
  5515.   /* It is now illegal to assign unions which contain members that
  5516.      have non-default assignment operators.  */
  5517.   if (! flag_traditional && TREE_CODE (lhstype) == UNION_TYPE)
  5518.     {
  5519.       if (modifycode == INIT_EXPR && TYPE_GETS_INIT_REF (lhstype))
  5520.     {
  5521.       error ("invalid initialization of union containing members with X(X&) constructor");
  5522.       return error_mark_node;
  5523.     }
  5524.       else if (modifycode == NOP_EXPR && TYPE_GETS_ASSIGNMENT (lhstype))
  5525.     {
  5526.       error ("invalid assignment of union containing members with non-default operator=");
  5527.       return error_mark_node;
  5528.     }
  5529.     }
  5530.  
  5531.   /* If storing in a field that is in actuality a short or narrower than one,
  5532.      we must store in the field in its actual type.  */
  5533.  
  5534.   if (lhstype != TREE_TYPE (lhs))
  5535.     {
  5536.       lhs = copy_node (lhs);
  5537.       TREE_TYPE (lhs) = lhstype;
  5538.     }
  5539.  
  5540.   /* Convert new value to destination type.  */
  5541.  
  5542.   if (TREE_CODE (lhstype) == ARRAY_TYPE)
  5543.     {
  5544.       /* Have to wrap this in RTL_EXPR for two cases:
  5545.      in base or member initialization and if we
  5546.      are a branch of a ?: operator.  Since we
  5547.      can't easily know the latter, just do it always.  */
  5548.  
  5549.       result = make_node (RTL_EXPR);
  5550.  
  5551.       TREE_TYPE (result) = void_type_node;
  5552.       do_pending_stack_adjust ();
  5553.       start_sequence_for_rtl_expr (result);
  5554.  
  5555.       /* As a matter of principle, `start_sequence' should do this.  */
  5556.       emit_note (0, -1);
  5557.  
  5558.       expand_vec_init (lhs, lhs, array_type_nelts (lhstype), newrhs,
  5559.                1 + (modifycode != INIT_EXPR));
  5560.  
  5561.       do_pending_stack_adjust ();
  5562.  
  5563.       TREE_SIDE_EFFECTS (result) = 1;
  5564.       RTL_EXPR_SEQUENCE (result) = get_insns ();
  5565.       RTL_EXPR_RTL (result) = const0_rtx;
  5566.       end_sequence ();
  5567.       return result;
  5568.     }
  5569.  
  5570.   if (modifycode == INIT_EXPR)
  5571.     {
  5572.       newrhs = convert_for_initialization (lhs, lhstype, newrhs, LOOKUP_NORMAL,
  5573.                        "assignment", NULL_TREE, 0);
  5574.       if (lhs == DECL_RESULT (current_function_decl))
  5575.     {
  5576.       if (DECL_INITIAL (lhs))
  5577.         warning ("return value from function receives multiple initializations");
  5578.       DECL_INITIAL (lhs) = newrhs;
  5579.     }
  5580.     }
  5581.   else
  5582.     {
  5583.       if (IS_AGGR_TYPE (lhstype))
  5584.     {
  5585. #if 1
  5586.       if (TYPE_GETS_ASSIGNMENT (lhstype)
  5587.           && ! TYPE_HAS_ASSIGNMENT (lhstype))
  5588.         {
  5589.           cp_error ("assignment not defined for type `%T'", lhstype);
  5590.           return error_mark_node;
  5591.         }
  5592. #endif
  5593.       if (result = build_opfncall (MODIFY_EXPR,
  5594.                        LOOKUP_NORMAL, lhs, newrhs,
  5595.                        make_node (NOP_EXPR)))
  5596.         return result;
  5597.     }
  5598.       newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
  5599.                        NULL_TREE, 0);
  5600.       if (flag_elide_constructors == 0
  5601.       && TREE_CODE (newrhs) == CALL_EXPR
  5602.       && TREE_ADDRESSABLE (lhstype))
  5603.     {
  5604.       /* Can't initialized directly from a CALL_EXPR, since
  5605.          we don't know about what doesn't alias what.  */
  5606.  
  5607.       tree temp = get_temp_name (lhstype, 0);
  5608.       newrhs = build (COMPOUND_EXPR, lhstype,
  5609.               build_modify_expr (temp, INIT_EXPR, newrhs),
  5610.               temp);
  5611.     }
  5612.     }
  5613.  
  5614.   if (TREE_CODE (newrhs) == ERROR_MARK)
  5615.     return error_mark_node;
  5616.  
  5617.   if (TREE_CODE (newrhs) == COND_EXPR)
  5618.     {
  5619.       tree lhs1;
  5620.       tree cond = TREE_OPERAND (newrhs, 0);
  5621.  
  5622.       if (TREE_SIDE_EFFECTS (lhs))
  5623.     cond = build_compound_expr (tree_cons
  5624.                     (NULL_TREE, lhs,
  5625.                      build_tree_list (NULL_TREE, cond)));
  5626.  
  5627.       /* Cannot have two identical lhs on this one tree (result) as preexpand
  5628.      calls will rip them out and fill in RTL for them, but when the
  5629.      rtl is generated, the calls will only be in the first side of the
  5630.      condition, not on both, or before the conditional jump! (mrs) */
  5631.       lhs1 = break_out_calls (lhs);
  5632.  
  5633.       if (lhs == lhs1)
  5634.     /* If there's no change, the COND_EXPR behaves like any other rhs.  */
  5635.     result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
  5636.             lhstype, lhs, newrhs);
  5637.       else
  5638.     {
  5639.       tree result_type = TREE_TYPE (newrhs);
  5640.       /* We have to convert each arm to the proper type because the
  5641.          types may have been munged by constant folding.  */
  5642.       result
  5643.         = build (COND_EXPR, result_type, cond,
  5644.              build_modify_expr (lhs, modifycode,
  5645.                     convert (result_type,
  5646.                          TREE_OPERAND (newrhs, 1))),
  5647.              build_modify_expr (lhs1, modifycode,
  5648.                     convert (result_type,
  5649.                          TREE_OPERAND (newrhs, 2))));
  5650.     }
  5651.     }
  5652.   else if (modifycode != INIT_EXPR && TREE_CODE (newrhs) == WITH_CLEANUP_EXPR)
  5653.     {
  5654.       tree cleanup = TREE_OPERAND (newrhs, 2);
  5655.       tree slot;
  5656.  
  5657.       /* Finish up by running cleanups and having the "value" of the lhs.  */
  5658.       tree exprlist = tree_cons (NULL_TREE, cleanup,
  5659.                  build_tree_list (NULL_TREE, lhs));
  5660.       newrhs = TREE_OPERAND (newrhs, 0);
  5661.       if (TREE_CODE (newrhs) == TARGET_EXPR)
  5662.       slot = TREE_OPERAND (newrhs, 0);
  5663.       else if (TREE_CODE (newrhs) == ADDR_EXPR)
  5664.     {
  5665.       /* Bad but legal.  */
  5666.       slot = newrhs;
  5667.       warning ("address taken of temporary object");
  5668.     }
  5669.       else
  5670.     my_friendly_abort (118);
  5671.  
  5672.       /* Copy the value computed in SLOT into LHS.  */
  5673.       exprlist = tree_cons (NULL_TREE,
  5674.                 build_modify_expr (lhs, modifycode, slot),
  5675.                 exprlist);
  5676.       /* Evaluate the expression that needs CLEANUP.  This will
  5677.      compute the value into SLOT.  */
  5678.       exprlist = tree_cons (NULL_TREE, newrhs, exprlist);
  5679.       result = convert (lhstype, build_compound_expr (exprlist));
  5680.     }
  5681.   else
  5682.     result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
  5683.             lhstype, lhs, newrhs);
  5684.   TREE_SIDE_EFFECTS (result) = 1;
  5685.  
  5686.   /* If we got the LHS in a different type for storing in,
  5687.      convert the result back to the nominal type of LHS
  5688.      so that the value we return always has the same type
  5689.      as the LHS argument.  */
  5690.  
  5691.   if (olhstype == TREE_TYPE (result))
  5692.     return result;
  5693.   return convert_for_assignment (olhstype, result, "assignment",
  5694.                  NULL_TREE, 0);
  5695. }
  5696.  
  5697.  
  5698. /* Return 0 if EXP is not a valid lvalue in this language
  5699.    even though `lvalue_or_else' would accept it.  */
  5700.  
  5701. int
  5702. language_lvalue_valid (exp)
  5703.      tree exp;
  5704. {
  5705.   return 1;
  5706. }
  5707.  
  5708. /* Build a constructor for a pointer to member function.  It can be
  5709.    used to initialize global variables, local variable, or used
  5710.    as a value in expressions.  TYPE is the POINTER to METHOD_TYPE we
  5711.    want to be.  */
  5712.  
  5713. tree
  5714. build_ptrmemfunc (type, pfn)
  5715.      tree type, pfn;
  5716. {
  5717.   tree index;
  5718.   tree delta = integer_zero_node;
  5719.   tree delta2 = integer_zero_node;
  5720.   tree vfield_offset;
  5721.   tree npfn;
  5722.   tree u;
  5723.  
  5724.   /* Handle null pointer to member function conversions. */
  5725.   if (integer_zerop (pfn))
  5726.     {
  5727.       pfn = build_c_cast (type, integer_zero_node);
  5728.       u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, pfn, NULL_TREE));
  5729.       return build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, integer_zero_node,
  5730.                           tree_cons (NULL_TREE, integer_zero_node,
  5731.                                  tree_cons (NULL_TREE, u, NULL_TREE))));
  5732.     }
  5733.  
  5734.   /* Allow pointer to member conversions here. */
  5735.   if (type != TREE_TYPE (pfn))
  5736.     {
  5737.       tree binfo
  5738.     = get_binfo (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn))),
  5739.              TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
  5740.              1);
  5741.       if (binfo == error_mark_node)
  5742.     {
  5743.       error ("   in pointer to member function conversion");
  5744.       return NULL_TREE;
  5745.     }
  5746.       if (binfo == 0)
  5747.     {
  5748.       error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn))),
  5749.                    TYPE_METHOD_BASETYPE (TREE_TYPE (type)));
  5750.       error ("   in pointer to member function conversion");
  5751.       return NULL_TREE;
  5752.     }
  5753.       if (TREE_VIA_VIRTUAL (binfo))
  5754.     {
  5755.       sorry ("pointer to member conversion from virtual base class");
  5756.     }
  5757.       delta = BINFO_OFFSET (binfo);
  5758.       delta2 = size_binop (PLUS_EXPR, delta2, delta);
  5759.     }
  5760.   
  5761.  
  5762.   if (TREE_CODE (TREE_OPERAND (pfn, 0)) != FUNCTION_DECL)
  5763.     warning ("assuming pointer to member function is non-virtual");
  5764.  
  5765.   if (TREE_CODE (TREE_OPERAND (pfn, 0)) == FUNCTION_DECL
  5766.       && DECL_VINDEX (TREE_OPERAND (pfn, 0)))
  5767.     {
  5768.       /* Find the offset to the vfield pointer in the object. */
  5769.       vfield_offset = TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn)));
  5770.       vfield_offset = CLASSTYPE_VFIELD (vfield_offset);
  5771.       vfield_offset = DECL_FIELD_BITPOS (vfield_offset);
  5772.       vfield_offset = size_binop (FLOOR_DIV_EXPR, vfield_offset, size_int (BITS_PER_UNIT));
  5773.       delta2 = size_binop (PLUS_EXPR, vfield_offset, delta2);
  5774.  
  5775.       /* Map everything down one to make room for the null pointer to member.  */
  5776.       index = size_binop (PLUS_EXPR,
  5777.               DECL_VINDEX (TREE_OPERAND (pfn, 0)),
  5778.               integer_one_node);
  5779.       u = build_nt (CONSTRUCTOR, 0, tree_cons (delta2_identifier, delta2, NULL_TREE));
  5780.  
  5781.       return build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
  5782.                           tree_cons (NULL_TREE, index,
  5783.                                  tree_cons (NULL_TREE, u, NULL_TREE))));
  5784.     }
  5785.   else
  5786.     index = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
  5787.  
  5788.   npfn = build1 (NOP_EXPR, type, pfn);
  5789.   TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
  5790.  
  5791.   u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, npfn, NULL_TREE));
  5792.  
  5793.   return build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
  5794.                           tree_cons (NULL_TREE, index,
  5795.                              tree_cons (NULL_TREE, u, NULL_TREE))));
  5796. }
  5797.  
  5798. /* Convert value RHS to type TYPE as preparation for an assignment
  5799.    to an lvalue of type TYPE.
  5800.    The real work of conversion is done by `convert'.
  5801.    The purpose of this function is to generate error messages
  5802.    for assignments that are not allowed in C.
  5803.    ERRTYPE is a string to use in error messages:
  5804.    "assignment", "return", etc.
  5805.  
  5806.    C++: attempts to allow `convert' to find conversions involving
  5807.    implicit type conversion between aggregate and scalar types
  5808.    as per 8.5.6 of C++ manual.  Does not randomly dereference
  5809.    pointers to aggregates!  */
  5810.  
  5811. static tree
  5812. convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
  5813.      tree type, rhs;
  5814.      char *errtype;
  5815.      tree fndecl;
  5816.      int parmnum;
  5817. {
  5818.   register enum tree_code codel = TREE_CODE (type);
  5819.   register tree rhstype;
  5820.   register enum tree_code coder = TREE_CODE (TREE_TYPE (rhs));
  5821.  
  5822.   if (coder == UNKNOWN_TYPE)
  5823.     rhs = instantiate_type (type, rhs, 1);
  5824.  
  5825.   if (coder == ERROR_MARK)
  5826.     return error_mark_node;
  5827.  
  5828.   if (codel == OFFSET_TYPE)
  5829.     {
  5830.       type = TREE_TYPE (type);
  5831.       codel = TREE_CODE (type);
  5832.     }
  5833.  
  5834.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  5835.   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
  5836.     rhs = TREE_OPERAND (rhs, 0);
  5837.  
  5838.   if (rhs == error_mark_node)
  5839.     return error_mark_node;
  5840.  
  5841.   if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
  5842.     {
  5843.       rhs = resolve_offset_ref (rhs);
  5844.       if (rhs == error_mark_node)
  5845.     return error_mark_node;
  5846.       rhstype = TREE_TYPE (rhs);
  5847.       coder = TREE_CODE (rhstype);
  5848.     }
  5849.  
  5850.   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  5851.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
  5852.       || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
  5853.     rhs = default_conversion (rhs);
  5854.   else if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
  5855.     rhs = convert_from_reference (rhs);
  5856.  
  5857.   rhstype = TREE_TYPE (rhs);
  5858.   coder = TREE_CODE (rhstype);
  5859.  
  5860.   /* This should no longer change types on us.  */
  5861.   if (TREE_CODE (rhs) == CONST_DECL)
  5862.     rhs = DECL_INITIAL (rhs);
  5863.   else if (TREE_READONLY_DECL_P (rhs))
  5864.     rhs = decl_constant_value (rhs);
  5865.  
  5866.   if (type == rhstype)
  5867.     {
  5868.       overflow_warning (rhs);
  5869.       return rhs;
  5870.     }
  5871.  
  5872. #ifdef OBJCPLUS
  5873.   /* Check for Objective-C protocols.  */
  5874.   if (maybe_objc_comptypes (type, rhstype, 0) == 1)
  5875.     return rhs;
  5876. #endif /* OBJCPLUS */
  5877.  
  5878.   if (coder == VOID_TYPE)
  5879.     {
  5880.       error ("void value not ignored as it ought to be");
  5881.       return error_mark_node;
  5882.     }
  5883.   /* Arithmetic types all interconvert.  */
  5884.   if ((codel == INTEGER_TYPE || codel == REAL_TYPE)
  5885.        && (coder == INTEGER_TYPE || coder == REAL_TYPE))
  5886.     {
  5887.       /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE.  */
  5888.       if (coder == REAL_TYPE && codel == INTEGER_TYPE)
  5889.     warn_for_assignment ("float or double assigned to integer data type",
  5890.                  "float or double used for argument %d of `%s'",
  5891.                  errtype, fndecl, parmnum, 0);
  5892.       /* And we should warn if assigning a negative value to
  5893.      an unsigned variable.  */
  5894.       else if (TREE_UNSIGNED (type))
  5895.     {
  5896.       if (TREE_CODE (rhs) == INTEGER_CST
  5897.           && TREE_NEGATED_INT (rhs))
  5898.         warn_for_assignment ("negative value assigned to unsigned quantity",
  5899.                  "negative value passed as argument %d of `%s'",
  5900.                  errtype, fndecl, parmnum, 0);
  5901.       overflow_warning (rhs);
  5902.       if (TREE_CONSTANT (rhs))
  5903.         rhs = fold (rhs);
  5904.     }
  5905.  
  5906.       return convert_and_check (type, rhs);
  5907.     }
  5908.   /* Conversions involving enums.  */
  5909.   else if ((codel == ENUMERAL_TYPE
  5910.         && (coder == ENUMERAL_TYPE || coder == INTEGER_TYPE || coder == REAL_TYPE))
  5911.        || (coder == ENUMERAL_TYPE
  5912.            && (codel == ENUMERAL_TYPE || codel == INTEGER_TYPE || codel == REAL_TYPE)))
  5913.     {
  5914.       extern int warn_enum_clash;
  5915.  
  5916.       if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
  5917.     return convert (type, rhs);
  5918.       if (warn_enum_clash)
  5919.     {
  5920.       if (codel == ENUMERAL_TYPE && coder == ENUMERAL_TYPE)
  5921.         message_2_types (warning, "conversion between incompatible enumeral types `%s' and `%s'",
  5922.                  type, rhstype);
  5923.       else if (coder == REAL_TYPE)
  5924.         warn_for_assignment ("float or double assigned to enumeral data type",
  5925.                  "float or double passed as enumeral data type for argument %d of `%s'",
  5926.                  errtype, fndecl, parmnum, pedantic);
  5927.       else if (codel == REAL_TYPE)
  5928.         warn_for_assignment ("enumeral value assigned to real data type",
  5929.                  "enumeral value passed as real data type for argument %d of `%s'",
  5930.                  errtype, fndecl, parmnum, pedantic);
  5931.       else if (coder == INTEGER_TYPE)
  5932.         warn_for_assignment ("assignment of integer to enumeral data type",
  5933.                  "passing integer as enumeral data type for argument %d of `%s'",
  5934.                  errtype, fndecl, parmnum, pedantic);
  5935.     }
  5936.       return convert (type, rhs);
  5937.     }
  5938.   /* Conversions among pointers */
  5939.   else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
  5940.     {
  5941.       register tree ttl = TREE_TYPE (type);
  5942.       register tree ttr = TREE_TYPE (rhstype);
  5943.  
  5944. #ifdef OBJCPLUS
  5945.       if (maybe_objc_comptypes (ttl, ttr, 0) == 1)
  5946.     return convert (type, rhs);
  5947. #endif /* OBJCPLUS */
  5948.  
  5949.       /* If both pointers are of aggregate type, then we
  5950.      can give better error messages, and save some work
  5951.      as well.  */
  5952.       if (TREE_CODE (ttl) == RECORD_TYPE && TREE_CODE (ttr) == RECORD_TYPE)
  5953.     {
  5954.       tree binfo;
  5955.  
  5956.       if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr)
  5957.           || type == class_star_type_node
  5958.           || rhstype == class_star_type_node)
  5959.         binfo = TYPE_BINFO (ttl);
  5960.       else
  5961.         binfo = get_binfo (ttl, ttr, 1);
  5962.  
  5963.       if (binfo == error_mark_node)
  5964.         return error_mark_node;
  5965.       if (binfo == 0)
  5966.         return error_not_base_type (ttl, ttr);
  5967.  
  5968.       if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  5969.         warn_for_assignment ("%s of non-`const *' pointer from `const *'",
  5970.                  "pointer to const given for argument %d of `%s'",
  5971.                  errtype, fndecl, parmnum, 0);
  5972.       if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  5973.         warn_for_assignment ("%s of non-`volatile *' pointer from `volatile *'",
  5974.                  "pointer to volatile given for argument %d of `%s'",
  5975.                  errtype, fndecl, parmnum, 0);
  5976.     }
  5977.  
  5978.       /* Any non-function converts to a [const][volatile] void *
  5979.      and vice versa; otherwise, targets must be the same.
  5980.      Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
  5981.       else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  5982.            || TYPE_MAIN_VARIANT (ttr) == void_type_node
  5983.            || comp_target_types (type, rhstype, 1)
  5984.            || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
  5985.            == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
  5986.     {
  5987.       /* ARM $4.8, commentary on p39.  */
  5988.       if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  5989.           && TREE_CODE (ttr) == OFFSET_TYPE)
  5990.         {
  5991.           error ("no standard conversion from pointer to member to `void *'");
  5992.           return error_mark_node;
  5993.         }
  5994.  
  5995.       if (TYPE_MAIN_VARIANT (ttl) != void_type_node
  5996.           && TYPE_MAIN_VARIANT (ttr) == void_type_node
  5997.           && rhs != null_pointer_node)
  5998.         pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
  5999.              errtype);
  6000.       else if (pedantic
  6001.           && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
  6002.            && (TREE_CODE (ttr) == FUNCTION_TYPE
  6003.                || TREE_CODE (ttr) == METHOD_TYPE))
  6004.           ||
  6005.           (TYPE_MAIN_VARIANT (ttr) == void_type_node
  6006.            && (TREE_CODE (ttl) == FUNCTION_TYPE
  6007.                || TREE_CODE (ttl) == METHOD_TYPE))))
  6008.         warn_for_assignment ("%s between function pointer and `void *'",
  6009.                  "function pointer and `void *' incompatible; argument %d of `%s'",
  6010.                  errtype, fndecl, parmnum, flag_pedantic_errors);
  6011.       /* Const and volatile mean something different for function types,
  6012.          so the usual warnings are not appropriate.  */
  6013.       else if ((TREE_CODE (ttr) != FUNCTION_TYPE && TREE_CODE (ttr) != METHOD_TYPE)
  6014.            || (TREE_CODE (ttl) != FUNCTION_TYPE && TREE_CODE (ttl) != METHOD_TYPE))
  6015.         {
  6016.           if (TREE_CODE (ttl) == OFFSET_TYPE
  6017.           && binfo_member (TYPE_OFFSET_BASETYPE (ttr),
  6018.                    CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl))))
  6019.         {
  6020.           sorry ("%s between pointer to members converting across virtual baseclasses", errtype);
  6021.           return error_mark_node;
  6022.         }
  6023.           if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  6024.         warn_for_assignment ("%s of non-`const *' pointer from `const *'",
  6025.                      "pointer to const given for argument %d of `%s'",
  6026.                      errtype, fndecl, parmnum, flag_pedantic_errors);
  6027.           if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  6028.         warn_for_assignment ("%s of non-`volatile *' pointer from `volatile *'",
  6029.                      "pointer to volatile given for argument %d of `%s'",
  6030.                      errtype, fndecl, parmnum, flag_pedantic_errors);
  6031.         }
  6032.     }
  6033.       else if (TREE_CODE (ttr) == OFFSET_TYPE
  6034.            && TREE_CODE (ttl) != OFFSET_TYPE)
  6035.     {
  6036.       /* Normally, pointers to different type codes (other
  6037.          than void) are not compatible, but we perform
  6038.          some type instantiation if that resolves the
  6039.          ambiguity of (X Y::*) and (X *).  */
  6040.  
  6041.       if (current_class_decl)
  6042.         {
  6043.           if (TREE_CODE (rhs) == INTEGER_CST)
  6044.         {
  6045.           rhs = build (PLUS_EXPR, build_pointer_type (TREE_TYPE (ttr)),
  6046.                    current_class_decl, rhs);
  6047.           return convert_for_assignment (type, rhs,
  6048.                          errtype, fndecl, parmnum);
  6049.         }
  6050.         }
  6051.       if (TREE_CODE (ttl) == METHOD_TYPE)
  6052.         error ("%s between pointer-to-method and pointer-to-member types",
  6053.            errtype);
  6054.       else
  6055.         error ("%s between pointer and pointer-to-member types", errtype);
  6056.       return error_mark_node;
  6057.     }
  6058.       else
  6059.     {
  6060.       int const_parity = TYPE_READONLY (type) ^ TYPE_READONLY (rhstype);
  6061.       int volatile_parity = TYPE_VOLATILE (type) ^ TYPE_VOLATILE (rhstype);
  6062.       int unsigned_parity;
  6063.       int nptrs = 0;
  6064.  
  6065.       while (TREE_CODE (ttl) == POINTER_TYPE
  6066.          && TREE_CODE (ttr) == POINTER_TYPE)
  6067.         {
  6068.           nptrs -= 1;
  6069.           const_parity |= TYPE_READONLY (ttl) ^ TYPE_READONLY (ttr);
  6070.           volatile_parity |= TYPE_VOLATILE (ttl) ^ TYPE_VOLATILE (ttr);
  6071.           ttl = TREE_TYPE (ttl);
  6072.           ttr = TREE_TYPE (ttr);
  6073.         }
  6074.       unsigned_parity = TREE_UNSIGNED (ttl) - TREE_UNSIGNED (ttr);
  6075.       if (unsigned_parity)
  6076.         if (TREE_UNSIGNED (ttl))
  6077.           ttr = unsigned_type (ttr);
  6078.         else
  6079.           ttl = unsigned_type (ttl);
  6080.  
  6081.       if (comp_target_types (ttl, ttr, nptrs))
  6082.         {
  6083.           if (const_parity)
  6084.         warn_for_assignment ("%s of non-`const *' pointer from `const *'",
  6085.                      "pointer to const given for argument %d of `%s'",
  6086.                      errtype, fndecl, parmnum, 0);
  6087.           if (volatile_parity)
  6088.         warn_for_assignment ("%s of non-`volatile *' pointer from volatile *",
  6089.                      "pointer to volatile given for argument %d of `%s'",
  6090.                      errtype, fndecl, parmnum, 0);
  6091.           if (unsigned_parity > 0)
  6092.         warn_for_assignment ("%s of unsigned pointer from signed pointer",
  6093.                      "passing signed pointer to unsigned pointer argument %d of `%s'",
  6094.                      errtype, fndecl, parmnum, flag_pedantic_errors);
  6095.           else if (unsigned_parity < 0)
  6096.         warn_for_assignment ("%s of signed pointer from unsigned pointer",
  6097.                      "passing unsigned pointer to signed pointer argument %d of `%s'",
  6098.                      errtype, fndecl, parmnum, flag_pedantic_errors);
  6099.  
  6100.           /* C++ is not so friendly about converting function and
  6101.          member function pointers as C.  Emit warnings here.  */
  6102.           if (TREE_CODE (ttl) == FUNCTION_TYPE
  6103.           || TREE_CODE (ttl) == METHOD_TYPE)
  6104.         if (! comptypes (ttl, ttr, 0))
  6105.           {
  6106.             char *tmpbuf, *lhsbuf;
  6107.             char *rhsbuf;
  6108.             tree null_name = get_identifier ("");
  6109.             tree lhs = build_decl (FUNCTION_DECL, null_name, ttl);
  6110.             tree rhs = build_decl (FUNCTION_DECL, null_name, ttr);
  6111.             tmpbuf = fndecl_as_string (0, lhs, 1);
  6112.             lhsbuf = (char *) alloca (strlen (tmpbuf)+1);
  6113.             strcpy (lhsbuf, tmpbuf);
  6114.             rhsbuf = fndecl_as_string (0, rhs, 1);
  6115.             warning ("conflicting function types in %s:", errtype);
  6116.             warning ("\t`%s' != `%s'", lhsbuf, rhsbuf);
  6117.           }
  6118.         }
  6119.       else if (TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
  6120.         {
  6121.           /* When does this happen?  */
  6122.           my_friendly_abort (119);
  6123.           /* Conversion of a pointer-to-member type to void *.  */
  6124.           rhs = build_unary_op (ADDR_EXPR, rhs, 0);
  6125.           TREE_TYPE (rhs) = type;
  6126.           return rhs;
  6127.         }
  6128.       else if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
  6129.         {
  6130.           /* When does this happen?  */
  6131.           my_friendly_abort (120);
  6132.           /* Conversion of a pointer-to-member type to void *.  */
  6133.           rhs = build_unary_op (ADDR_EXPR, rhs, 0);
  6134.           TREE_TYPE (rhs) = type;
  6135.           return rhs;
  6136.         }
  6137.       else
  6138.         {
  6139.           if (fndecl)
  6140.         error ("incompatible pointer types for argument %d of `%s'",
  6141.                parmnum + 1, lang_printable_name (fndecl));
  6142.           else
  6143.         error ("%s between incompatible pointer types", errtype);
  6144.           return error_mark_node;
  6145.         }
  6146.     }
  6147.       return convert (type, rhs);
  6148.     }
  6149.   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
  6150.     {
  6151.       /* An explicit constant 0 can convert to a pointer,
  6152.          but not a 0 that results from casting or folding.  */
  6153.       if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs)))
  6154.     {
  6155.       warn_for_assignment ("%s of pointer from integer lacks a cast",
  6156.                    "passing integer to pointer argument %d of `%s' lacks a cast",
  6157.                    errtype, fndecl, parmnum, flag_pedantic_errors);
  6158.       return convert (type, rhs);
  6159.     }
  6160.       return null_pointer_node;
  6161.     }
  6162.   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
  6163.     {
  6164.       warn_for_assignment ("%s of integer from pointer lacks a cast",
  6165.                "passing pointer to integer argument %d of `%s' lacks a cast",
  6166.                errtype, fndecl, parmnum, flag_pedantic_errors);
  6167.       return convert (type, rhs);
  6168.     }
  6169.  
  6170.   /* C++ */
  6171.   else if (((coder == POINTER_TYPE && TREE_CODE (rhs) == ADDR_EXPR
  6172.          && TREE_CODE (rhstype) == POINTER_TYPE
  6173.          && TREE_CODE (TREE_TYPE (rhstype)) == METHOD_TYPE)
  6174.         || integer_zerop (rhs))
  6175.        && TYPE_PTRMEMFUNC_P (type))
  6176.     {
  6177.       /* compatible pointer to member functions. */
  6178.       rhs = build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), rhs);
  6179.       if (rhs == 0)
  6180.     return error_mark_node;
  6181.       return digest_init (type, rhs, (tree *)0);
  6182.     }
  6183.   else if (codel == ERROR_MARK || coder == ERROR_MARK)
  6184.     return error_mark_node;
  6185.  
  6186.   /* This should no longer happen.  References are initialized via
  6187.      `convert_for_initialization'.  They should otherwise be
  6188.      bashed before coming here.  */
  6189.   else if (codel == REFERENCE_TYPE)
  6190.     /* Force an abort.  */
  6191.     my_friendly_assert (codel != REFERENCE_TYPE, 317);
  6192.   else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs)))
  6193.     return build1 (NOP_EXPR, type, rhs);
  6194.   else if (TYPE_HAS_CONSTRUCTOR (type) || IS_AGGR_TYPE (TREE_TYPE (rhs)))
  6195.     return convert (type, rhs);
  6196.  
  6197.   error ("incompatible types in %s", errtype);
  6198.   return error_mark_node;
  6199. }
  6200.  
  6201. /* Print a warning using either ANON_MSG or NAMED_MSG.
  6202.    ANON_MSG is used if DECL and FUNCTION are 0; it gets one parameter, OPNAME.
  6203.    NAMED_MSG is used if DECL is non-0;
  6204.    it gets two parameters, the name of DECL and that of FUNCTION.
  6205.    FUNCTION_MSG is used if DECL is 0 and FUNCTION is non-0;
  6206.    it gets one parameter, the name FUNCTION.
  6207.  
  6208.    If SEVERE is non-0, the report an error instead of a warning.
  6209.  
  6210.    If FNDECL is nonzero, the message concerns an argument in a call
  6211.    to that function.  ARGNUM is the number of the argument, origin 0.  */
  6212.  
  6213. void
  6214. warn_for_assignment (anon_msg, arg_msg, opname, fndecl, argnum, severe)
  6215.      char *anon_msg;
  6216.      char *arg_msg;
  6217.      char *opname;
  6218.      tree fndecl;
  6219.      int argnum;
  6220.      int severe;
  6221. {
  6222.   if (fndecl)
  6223.     {
  6224.       if (argnum < 0)
  6225.     {
  6226.       char *buf = (char *)alloca (strlen (arg_msg) + 1);
  6227.       char *p;
  6228.       strcpy (buf, arg_msg);
  6229.       for (p = buf; *p; p++)
  6230.         if (p[0] == '%' && p[1] == 'd')
  6231.           {
  6232.         p[1] = 's';
  6233.         if (severe)
  6234.           error (buf, "`this'", lang_printable_name (fndecl));
  6235.         else
  6236.           warning (buf, "`this'", lang_printable_name (fndecl));
  6237.         break;
  6238.           }
  6239.     }
  6240.       else if (severe)
  6241.     error (arg_msg, argnum + 1, lang_printable_name (fndecl));
  6242.       else
  6243.     warning (arg_msg, argnum + 1, lang_printable_name (fndecl));
  6244.     }
  6245.   else if (severe)
  6246.     error (anon_msg, opname);
  6247.   else
  6248.     warning (anon_msg, opname);
  6249. }
  6250.  
  6251. /* Convert RHS to be of type TYPE.  If EXP is non-zero,
  6252.    it is the target of the initialization.
  6253.    ERRTYPE is a string to use in error messages.
  6254.  
  6255.    Two major differences between the behavior of
  6256.    `convert_for_assignment' and `convert_for_initialization'
  6257.    are that references are bashed in the former, while
  6258.    copied in the latter, and aggregates are assigned in
  6259.    the former (operator=) while initialized in the
  6260.    latter (X(X&)).
  6261.  
  6262.    If using constructor make sure no conversion operator exists, if one does
  6263.    exist, an ambiguity exists.  */
  6264. tree
  6265. convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
  6266.      tree exp, type, rhs;
  6267.      int flags;
  6268.      char *errtype;
  6269.      tree fndecl;
  6270.      int parmnum;
  6271. {
  6272.   register enum tree_code codel = TREE_CODE (type);
  6273.   register tree rhstype;
  6274.   register enum tree_code coder;
  6275.  
  6276.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  6277.      Strip such NOP_EXPRs, since RHS is used in non-lvalue context.  */
  6278.   if (TREE_CODE (rhs) == NOP_EXPR
  6279.       && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0)))
  6280.     rhs = TREE_OPERAND (rhs, 0);
  6281.  
  6282.   if (rhs == error_mark_node
  6283.       || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
  6284.     return error_mark_node;
  6285.  
  6286.   if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
  6287.     {
  6288.       rhs = resolve_offset_ref (rhs);
  6289.       if (rhs == error_mark_node)
  6290.     return error_mark_node;
  6291.       rhstype = TREE_TYPE (rhs);
  6292.       coder = TREE_CODE (rhstype);
  6293.     }
  6294.  
  6295.   if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  6296.        && TREE_CODE (type) != ARRAY_TYPE && TREE_CODE (type) != REFERENCE_TYPE)
  6297.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
  6298.       || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
  6299.     rhs = default_conversion (rhs);
  6300.  
  6301.   rhstype = TREE_TYPE (rhs);
  6302.   coder = TREE_CODE (rhstype);
  6303.  
  6304.   if (coder == UNKNOWN_TYPE)
  6305.     {
  6306.       rhs = instantiate_type (type, rhs, 1);
  6307.       rhstype = TREE_TYPE (rhs);
  6308.       coder = TREE_CODE (rhstype);
  6309.     }
  6310.  
  6311.   if (coder == ERROR_MARK)
  6312.     return error_mark_node;
  6313.  
  6314. #if 0
  6315.   /* This is *not* the quick way out!  It is the way to disaster.  */
  6316.   if (type == rhstype)
  6317.     goto converted;
  6318. #endif
  6319.  
  6320.   /* We accept references to incomplete types, so we can
  6321.      return here before checking if RHS is of complete type.  */
  6322.      
  6323.   if (codel == REFERENCE_TYPE)
  6324.     return convert_to_reference ((exp ? exp : error_mark_node),
  6325.                   type, rhs, fndecl, parmnum, errtype,
  6326.                  0, flags);
  6327.  
  6328.   rhs = require_complete_type (rhs);
  6329.   if (rhs == error_mark_node)
  6330.     return error_mark_node;
  6331.  
  6332.   if (exp != 0) exp = require_complete_type (exp);
  6333.   if (exp == error_mark_node)
  6334.     return error_mark_node;
  6335.  
  6336.   if (TREE_CODE (rhstype) == REFERENCE_TYPE)
  6337.     rhstype = TREE_TYPE (rhstype);
  6338.  
  6339.   if (IS_AGGR_TYPE (type) && TYPE_NEEDS_CONSTRUCTOR (type))
  6340.     {
  6341.       if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
  6342.     {
  6343.       /* This is sufficient to perform initialization.  No need, apparently,
  6344.          to go through X(X&) to do first-cut initialization.  Return through
  6345.          a TARGET_EXPR so that we get cleanups if it is used.  */
  6346.       if (TREE_CODE (rhs) == CALL_EXPR)
  6347.         {
  6348.           rhs = build_cplus_new (type, rhs, 0);
  6349.           return rhs;
  6350.         }
  6351.       /* Handle the case of default parameter initialization and
  6352.          initialization of static variables.  */
  6353.       else if (TREE_CODE (rhs) == INDIRECT_REF && TREE_HAS_CONSTRUCTOR (rhs))
  6354.         {
  6355.           my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs, 0)) == CALL_EXPR, 318);
  6356.           if (exp)
  6357.         {
  6358.           my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1)) == NULL_TREE, 316);
  6359.           TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1))
  6360.             = build_unary_op (ADDR_EXPR, exp, 0);
  6361.         }
  6362.           else
  6363.         rhs = build_cplus_new (type, TREE_OPERAND (rhs, 0), 0);
  6364.           return rhs;
  6365.         }
  6366.     }
  6367.       if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)
  6368.       || (IS_AGGR_TYPE (rhstype) && UNIQUELY_DERIVED_FROM_P (type, rhstype)))
  6369.     {
  6370.       if (TYPE_HAS_INIT_REF (type))
  6371.         {
  6372.           tree init = build_method_call (exp, constructor_name_full (type),
  6373.                          build_tree_list (NULL_TREE, rhs),
  6374.                          NULL_TREE, LOOKUP_NORMAL);
  6375.  
  6376.           if (init == error_mark_node)
  6377.         return error_mark_node;
  6378.  
  6379.           if (exp == 0)
  6380.         {
  6381.           exp = build_cplus_new (type, init, 0);
  6382.           return exp;
  6383.         }
  6384.  
  6385.           return build (COMPOUND_EXPR, type, init, exp);
  6386.         }
  6387.  
  6388. #if 0
  6389.       /* ??? The following warnings are turned off because
  6390.          this is another place where the default X(X&) constructor
  6391.          is implemented.  */
  6392.       if (TYPE_HAS_ASSIGNMENT (type))
  6393.         warning ("bitwise copy: `%s' defines operator=()",
  6394.              TYPE_NAME_STRING (type));
  6395.       else if (TYPE_GETS_ASSIGNMENT (type))
  6396.         warning ("bitwise copy: `%s' has a member with operator=()",
  6397.              TYPE_NAME_STRING (type));
  6398. #endif
  6399.  
  6400.       if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
  6401.         rhs = convert_from_reference (rhs);
  6402.       if (type != rhstype)
  6403.         return build1 (NOP_EXPR, type, rhs);
  6404.       return rhs;
  6405.     }
  6406.  
  6407.       return convert (type, rhs);
  6408.     }
  6409. #if 0
  6410.   /* ??? The following warnings are turned off because
  6411.      this is another place where the default X(X&) constructor
  6412.      is implemented.  */
  6413.   if (TYPE_LANG_SPECIFIC (type))
  6414.     {
  6415.       if (TYPE_HAS_ASSIGNMENT (type))
  6416.     warning ("bitwise copy: `%s' defines operator=()",
  6417.          TYPE_NAME_STRING (type));
  6418.       else if (TYPE_GETS_ASSIGNMENT (type))
  6419.     warning ("bitwise copy: `%s' has a member with operator=()",
  6420.          TYPE_NAME_STRING (type));
  6421.     }
  6422. #endif
  6423.  
  6424.   if (type == TREE_TYPE (rhs))
  6425.     {
  6426.       if (TREE_READONLY_DECL_P (rhs))
  6427.     rhs = decl_constant_value (rhs);
  6428.       return rhs;
  6429.     }
  6430.  
  6431.   return convert_for_assignment (type, rhs, errtype, fndecl, parmnum);
  6432. }
  6433.  
  6434. /* Expand an ASM statement with operands, handling output operands
  6435.    that are not variables or INDIRECT_REFS by transforming such
  6436.    cases into cases that expand_asm_operands can handle.
  6437.  
  6438.    Arguments are same as for expand_asm_operands.
  6439.  
  6440.    We don't do default conversions on all inputs, because it can screw
  6441.    up operands that are expected to be in memory.  */
  6442.  
  6443. void
  6444. c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
  6445.      tree string, outputs, inputs, clobbers;
  6446.      int vol;
  6447.      char *filename;
  6448.      int line;
  6449. {
  6450.   int noutputs = list_length (outputs);
  6451.   register int i;
  6452.   /* o[I] is the place that output number I should be written.  */
  6453.   register tree *o = (tree *) alloca (noutputs * sizeof (tree));
  6454.   register tree tail;
  6455.  
  6456.   /* Record the contents of OUTPUTS before it is modified.  */
  6457.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  6458.     o[i] = TREE_VALUE (tail);
  6459.  
  6460.   /* Generate the ASM_OPERANDS insn;
  6461.      store into the TREE_VALUEs of OUTPUTS some trees for
  6462.      where the values were actually stored.  */
  6463.   expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
  6464.  
  6465.   /* Copy all the intermediate outputs into the specified outputs.  */
  6466.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  6467.     {
  6468.       if (o[i] != TREE_VALUE (tail))
  6469.     {
  6470.       expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
  6471.                const0_rtx, VOIDmode, 0);
  6472.       free_temp_slots ();
  6473.     }
  6474.       /* Detect modification of read-only values.
  6475.      (Otherwise done by build_modify_expr.)  */
  6476.       else
  6477.     {
  6478.       tree type = TREE_TYPE (o[i]);
  6479.       if (TYPE_READONLY (type)
  6480.           || ((TREE_CODE (type) == RECORD_TYPE
  6481.            || TREE_CODE (type) == UNION_TYPE)
  6482.           && C_TYPE_FIELDS_READONLY (type)))
  6483.         readonly_error (o[i], "modification by `asm'", 1);
  6484.     }
  6485.     }
  6486.  
  6487.   /* Those MODIFY_EXPRs could do autoincrements.  */
  6488.   emit_queue ();
  6489. }
  6490.  
  6491. /* Expand a C `return' statement.
  6492.    RETVAL is the expression for what to return,
  6493.    or a null pointer for `return;' with no value.
  6494.  
  6495.    C++: upon seeing a `return', we must call destructors on all
  6496.    variables in scope which had constructors called on them.
  6497.    This means that if in a destructor, the base class destructors
  6498.    must be called before returning.
  6499.  
  6500.    The RETURN statement in C++ has initialization semantics.  */
  6501.  
  6502. void
  6503. c_expand_return (retval)
  6504.      tree retval;
  6505. {
  6506.   extern struct nesting *cond_stack, *loop_stack, *case_stack;
  6507.   extern tree dtor_label, ctor_label;
  6508.   tree result = DECL_RESULT (current_function_decl);
  6509.   tree valtype = TREE_TYPE (result);
  6510.   register int use_temp = 0;
  6511.   int returns_value = 1;
  6512.  
  6513.   if (TREE_THIS_VOLATILE (current_function_decl))
  6514.     warning ("function declared `volatile' has a `return' statement");
  6515.  
  6516.   if (retval == error_mark_node)
  6517.     {
  6518.       current_function_returns_null = 1;
  6519.       return;
  6520.     }
  6521.  
  6522.   if (retval == NULL_TREE)
  6523.     {
  6524.       /* A non-named return value does not count.  */
  6525.  
  6526.       /* Can't just return from a destructor.  */
  6527.       if (dtor_label)
  6528.     {
  6529.       expand_goto (dtor_label);
  6530.       return;
  6531.     }
  6532.  
  6533.       if (DECL_CONSTRUCTOR_P (current_function_decl))
  6534.     retval = current_class_decl;
  6535.       else if (DECL_NAME (result) != NULL_TREE
  6536.            && TREE_CODE (valtype) != VOID_TYPE)
  6537.     retval = result;
  6538.       else
  6539.     {
  6540.       current_function_returns_null = 1;
  6541.  
  6542.       if (valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
  6543.         {
  6544.           if (DECL_NAME (DECL_RESULT (current_function_decl)) == NULL_TREE)
  6545.         {
  6546.           pedwarn ("`return' with no value, in function returning non-void");
  6547.           /* Clear this, so finish_function won't say that we
  6548.              reach the end of a non-void function (which we don't,
  6549.              we gave a return!).  */
  6550.           current_function_returns_null = 0;
  6551.         }
  6552.         }
  6553.  
  6554.       expand_null_return ();
  6555.       return;
  6556.     }
  6557.     }
  6558.   else if (DECL_CONSTRUCTOR_P (current_function_decl)
  6559.        && retval != current_class_decl)
  6560.     {
  6561.       error ("return from a constructor: use `this = ...' instead");
  6562.       retval = current_class_decl;
  6563.     }
  6564.  
  6565.   if (valtype == NULL_TREE || TREE_CODE (valtype) == VOID_TYPE)
  6566.     {
  6567.       current_function_returns_null = 1;
  6568.       /* We do this here so we'll avoid a warning about how the function
  6569.      "may or may not return a value" in finish_function.  */
  6570.       returns_value = 0;
  6571.  
  6572.       if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
  6573.     pedwarn ("`return' with a value, in function returning void");
  6574.       expand_return (retval);
  6575.     }
  6576.   /* Add some useful error checking for C++.  */
  6577.   else if (TREE_CODE (valtype) == REFERENCE_TYPE)
  6578.     {
  6579.       tree whats_returned;
  6580.       tree tmp_result = result;
  6581.  
  6582.       /* Don't initialize directly into a non-BLKmode retval, since that
  6583.      could lose when being inlined by another caller.  (GCC can't
  6584.      read the function return register in an inline function when
  6585.      the return value is being ignored).  */
  6586.       if (result && TYPE_MODE (TREE_TYPE (tmp_result)) != BLKmode)
  6587.     tmp_result = 0;
  6588.  
  6589.       /* convert to reference now, so we can give error if we
  6590.      return an reference to a non-lvalue.  */
  6591.       retval = convert_for_initialization (tmp_result, valtype, retval,
  6592.                        LOOKUP_NORMAL, "return",
  6593.                        NULL_TREE, 0);
  6594.  
  6595.       /* Sort through common things to see what it is
  6596.      we are returning.  */
  6597.       whats_returned = retval;
  6598.       if (TREE_CODE (whats_returned) == COMPOUND_EXPR)
  6599.     {
  6600.       whats_returned = TREE_OPERAND (whats_returned, 1);
  6601.       if (TREE_CODE (whats_returned) == ADDR_EXPR)
  6602.         whats_returned = TREE_OPERAND (whats_returned, 0);
  6603.     }
  6604.       if (TREE_CODE (whats_returned) == ADDR_EXPR)
  6605.     {
  6606.       whats_returned = TREE_OPERAND (whats_returned, 0);
  6607.       while (TREE_CODE (whats_returned) == NEW_EXPR
  6608.          || TREE_CODE (whats_returned) == TARGET_EXPR
  6609.          || TREE_CODE (whats_returned) == WITH_CLEANUP_EXPR)
  6610.         /* Get the target.  */
  6611.         whats_returned = TREE_OPERAND (whats_returned, 0);
  6612.     }
  6613.  
  6614.       if (TREE_CODE (whats_returned) == VAR_DECL && DECL_NAME (whats_returned))
  6615.     {
  6616.       if (TEMP_NAME_P (DECL_NAME (whats_returned)))
  6617.         warning ("reference to non-lvalue returned");
  6618.       else if (! TREE_STATIC (whats_returned)
  6619.            && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned)))
  6620.         cp_warning_at ("reference to local variable `%D' returned", whats_returned);
  6621.     }
  6622.     }
  6623.   else if (TREE_CODE (retval) == ADDR_EXPR)
  6624.     {
  6625.       tree whats_returned = TREE_OPERAND (retval, 0);
  6626.  
  6627.       if (TREE_CODE (whats_returned) == TREE_LIST)
  6628.     whats_returned = TREE_VALUE (whats_returned);
  6629.  
  6630.       if (DECL_NAME (whats_returned)
  6631.       && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned))
  6632.       && !TREE_STATIC (whats_returned))
  6633.     cp_warning_at ("address of local variable `%D' returned", whats_returned);
  6634.     }
  6635.   
  6636.   /* Now deal with possible C++ hair:
  6637.      (1) Compute the return value.
  6638.      (2) If there are aggregate values with destructors which
  6639.      must be cleaned up, clean them (taking care
  6640.      not to clobber the return value).
  6641.      (3) If an X(X&) constructor is defined, the return
  6642.      value must be returned via that.  */
  6643.  
  6644.   if (retval == result
  6645.       /* Watch out for constructors, which "return" aggregates
  6646.      via initialization, but which otherwise "return" a pointer.  */
  6647.       || DECL_CONSTRUCTOR_P (current_function_decl))
  6648.     {
  6649.       /* This is just an error--it's already been reported.  */
  6650.       if (TYPE_SIZE (valtype) == NULL_TREE)
  6651.     return;
  6652.  
  6653.       if (TYPE_MODE (valtype) != BLKmode
  6654.       && any_pending_cleanups (1))
  6655.     {
  6656.       retval = get_temp_regvar (valtype, retval);
  6657.       use_temp = obey_regdecls;
  6658.     }
  6659.     }
  6660.   else if (IS_AGGR_TYPE (valtype) && TYPE_NEEDS_CONSTRUCTOR (valtype))
  6661.     {
  6662.       /* Throw away the cleanup that `build_functional_cast' gave us.  */
  6663.       if (TREE_CODE (retval) == WITH_CLEANUP_EXPR
  6664.       && TREE_CODE (TREE_OPERAND (retval, 0)) == TARGET_EXPR)
  6665.     retval = TREE_OPERAND (retval, 0);
  6666.       expand_aggr_init (result, retval, 0);
  6667.       DECL_INITIAL (result) = NULL_TREE;
  6668.       retval = 0;
  6669.     }
  6670.   else
  6671.     {
  6672.       if (TYPE_MODE (valtype) == VOIDmode)
  6673.     {
  6674.       if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode
  6675.           && warn_return_type)
  6676.         warning ("return of void value in function returning non-void");
  6677.       expand_expr_stmt (retval);
  6678.       retval = 0;
  6679.       result = 0;
  6680.     }
  6681.       else if (TYPE_MODE (valtype) != BLKmode
  6682.            && any_pending_cleanups (1))
  6683.     {
  6684.       retval = get_temp_regvar (valtype, retval);
  6685.       use_temp = obey_regdecls;
  6686.       result = 0;
  6687.     }
  6688.       else
  6689.     {
  6690.       retval = convert_for_initialization (result, valtype, retval,
  6691.                            LOOKUP_NORMAL,
  6692.                            "return", NULL_TREE, 0);
  6693.       DECL_INITIAL (result) = NULL_TREE;
  6694.     }
  6695.       if (retval == error_mark_node)
  6696.     return;
  6697.     }
  6698.  
  6699.   emit_queue ();
  6700.  
  6701.   if (retval != NULL_TREE
  6702.       && TREE_CODE_CLASS (TREE_CODE (retval)) == 'd'
  6703.       && cond_stack == 0 && loop_stack == 0 && case_stack == 0)
  6704.     current_function_return_value = retval;
  6705.  
  6706.   if (result)
  6707.     {
  6708.       /* Everything's great--RETVAL is in RESULT.  */
  6709.       if (original_result_rtx)
  6710.     store_expr (result, original_result_rtx, 0);
  6711.       else if (retval && retval != result)
  6712.     {
  6713.       /* Clear this out so the later call to decl_function_context
  6714.          won't end up bombing on us.  */
  6715.       if (DECL_CONTEXT (result) == error_mark_node)
  6716.         DECL_CONTEXT (result) = NULL_TREE;
  6717.       /* Here is where we finally get RETVAL into RESULT.
  6718.          `expand_return' does the magic of protecting
  6719.          RESULT from cleanups.  */
  6720.       retval = build (INIT_EXPR, TREE_TYPE (result), result, retval);
  6721.       TREE_SIDE_EFFECTS (retval) = 1;
  6722.       expand_return (retval);
  6723.     }
  6724.       else
  6725.     expand_return (result);
  6726.  
  6727.       use_variable (DECL_RTL (result));
  6728.       if (ctor_label  && TREE_CODE (ctor_label) != ERROR_MARK)
  6729.     expand_goto (ctor_label);
  6730.       else
  6731.     expand_null_return ();
  6732.     }
  6733.   else
  6734.     {
  6735.       /* We may still need to put RETVAL into RESULT.  */
  6736.       result = DECL_RESULT (current_function_decl);
  6737.       if (original_result_rtx)
  6738.     {
  6739.       /* Here we have a named return value that went
  6740.          into memory.  We can compute RETVAL into that.  */
  6741.       if (retval)
  6742.         expand_assignment (result, retval, 0, 0);
  6743.       else
  6744.         store_expr (result, original_result_rtx, 0);
  6745.       result = make_tree (TREE_TYPE (result), original_result_rtx);
  6746.     }
  6747.       else if (ctor_label && TREE_CODE (ctor_label) != ERROR_MARK)
  6748.     {
  6749.       /* Here RETVAL is CURRENT_CLASS_DECL, so there's nothing to do.  */
  6750.       expand_goto (ctor_label);
  6751.     }
  6752.       else if (retval)
  6753.     {
  6754.       /* Here is where we finally get RETVAL into RESULT.
  6755.          `expand_return' does the magic of protecting
  6756.          RESULT from cleanups.  */
  6757.       result = build (INIT_EXPR, TREE_TYPE (result), result, retval);
  6758.       TREE_SIDE_EFFECTS (result) = 1;
  6759.       expand_return (result);
  6760.     }
  6761.       else if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode)
  6762.     expand_return (result);
  6763.     }
  6764.  
  6765.   current_function_returns_value = returns_value;
  6766.   if (original_result_rtx)
  6767.     use_variable (original_result_rtx);
  6768.   if (use_temp)
  6769.     use_variable (DECL_RTL (DECL_RESULT (current_function_decl)));
  6770.  
  6771.   /* One way to clear out cleanups that EXPR might
  6772.      generate.  Note that this code will really be
  6773.      dead code, but that is ok--cleanups that were
  6774.      needed were handled by the magic of `return'.  */
  6775.   expand_cleanups_to (NULL_TREE);
  6776. }
  6777.  
  6778. /* Start a C switch statement, testing expression EXP.
  6779.    Return EXP if it is valid, an error node otherwise.  */
  6780.  
  6781. tree
  6782. c_expand_start_case (exp)
  6783.      tree exp;
  6784. {
  6785.   tree type = TREE_TYPE (exp);
  6786.   register enum tree_code code = TREE_CODE (type);
  6787.  
  6788.   if (IS_AGGR_TYPE_CODE (code))
  6789.     exp = build_type_conversion (CONVERT_EXPR, integer_type_node, exp, 1);
  6790.   else
  6791.     exp = default_conversion (exp);
  6792.   if (exp == NULL_TREE)
  6793.     {
  6794.       error ("switch quantity not an integer");
  6795.       exp = error_mark_node;
  6796.     }
  6797.   type = TREE_TYPE (exp);
  6798.   code = TREE_CODE (type);
  6799.  
  6800.   if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
  6801.     {
  6802.       error ("switch quantity not an integer");
  6803.       exp = error_mark_node;
  6804.     }
  6805.   else
  6806.     {
  6807.       tree index;
  6808.  
  6809.       exp = default_conversion (exp);
  6810.       type = TREE_TYPE (exp);
  6811.       index = get_unwidened (exp, 0);
  6812.       /* We can't strip a conversion from a signed type to an unsigned,
  6813.      because if we did, int_fits_type_p would do the wrong thing
  6814.      when checking case values for being in range,
  6815.      and it's too hard to do the right thing.  */
  6816.       if (TREE_UNSIGNED (TREE_TYPE (exp))
  6817.       == TREE_UNSIGNED (TREE_TYPE (index)))
  6818.     exp = index;
  6819.     }
  6820.  
  6821.   expand_start_case (1, exp, type, "switch statement");
  6822.  
  6823.   return exp;
  6824. }
  6825.  
  6826. /* C++ does not yet support type checking of format strings.  */
  6827.  
  6828. void
  6829. record_format_info (function_ident, is_scan, format_num, first_arg_num)
  6830.       tree function_ident;
  6831.       int is_scan;
  6832.       int format_num;
  6833.       int first_arg_num;
  6834. {}
  6835.